def test_send_reply_message_event_url(self): '''Sending a message with a specified event url should store the event url for sending events in the future''' yield self.create_channel( self.service, self.redis, TelnetServerTransport, id='channel-id') in_msg = TransportUserMessage( from_addr='+2789', to_addr='+1234', transport_name='channel-id', transport_type='_', transport_metadata={'foo': 'bar'}) yield self.api.inbounds.store_vumi_message('channel-id', in_msg) msg = yield Channel.send_reply_message( 'channel-id', self.message_sender, self.outbounds, self.inbounds, { 'reply_to': in_msg['message_id'], 'content': 'testcontent', 'event_url': 'http://test.org', }) event_url = yield self.outbounds.load_event_url( 'channel-id', msg['message_id']) self.assertEqual(event_url, 'http://test.org')
def test_send_reply_message(self): '''send_reply_message should place the correct reply message on the correct queue''' yield self.create_channel( self.service, self.redis, TelnetServerTransport, id='channel-id') in_msg = TransportUserMessage( from_addr='+2789', to_addr='+1234', transport_name='channel-id', transport_type='_', transport_metadata={'foo': 'bar'}) yield self.api.inbounds.store_vumi_message('channel-id', in_msg) msg = yield Channel.send_reply_message( 'channel-id', self.message_sender, self.outbounds, self.inbounds, { 'reply_to': in_msg['message_id'], 'content': 'testcontent', }) expected = in_msg.reply(content='testcontent') expected = conjoin(api_from_message(expected), { 'timestamp': msg['timestamp'], 'message_id': msg['message_id'] }) self.assertEqual(msg, expected) [dispatched] = self.get_dispatched_messages('channel-id.outbound') self.assertEqual(msg['message_id'], dispatched['message_id']) self.assertEqual(api_from_message(dispatched), expected)
def send_message(self, request, body, channel_id): '''Send an outbound (mobile terminated) message''' if 'to' not in body and 'reply_to' not in body: raise ApiUsageError( 'Either "to" or "reply_to" must be specified') if 'to' in body and 'reply_to' in body: raise ApiUsageError( 'Only one of "to" and "reply_to" may be specified') if 'from' in body and 'reply_to' in body: raise ApiUsageError( 'Only one of "from" and "reply_to" may be specified') try: self.service.getServiceNamed(channel_id) except KeyError: raise ChannelNotFound() if 'to' in body: msg = yield Channel.send_message( channel_id, self.message_sender, self.outbounds, body) else: msg = yield Channel.send_reply_message( channel_id, self.message_sender, self.outbounds, self.inbounds, body) returnValue(response(request, 'message sent', msg))
def test_send_reply_message_inbound_not_found(self): '''send_reply_message should raise an error if the inbound message is not found''' yield self.create_channel( self.service, self.redis, TelnetServerTransport, id='channel-id') self.assertFailure(Channel.send_reply_message( 'channel-id', self.message_sender, self.outbounds, self.inbounds, { 'reply_to': 'i-do-not-exist', 'content': 'testcontent', }), MessageNotFound)