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_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') msg = yield Channel.send_message( 'channel-id', self.message_sender, self.outbounds, { 'from': '+1234', '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_message(self): '''The send_message function should place the message on the correct queue''' yield self.create_channel( self.service, self.redis, TelnetServerTransport, id='channel-id') msg = yield Channel.send_message( 'channel-id', self.message_sender, self.outbounds, { 'from': '+1234', 'content': 'testcontent', }) self.assertEqual(msg['channel_id'], 'channel-id') self.assertEqual(msg['from'], '+1234') self.assertEqual(msg['content'], 'testcontent') [dispatched_message] = self.get_dispatched_messages( 'channel-id.outbound') self.assertEqual(msg['message_id'], dispatched_message['message_id'])