def send_message(self, sender, outbounds, msg): '''Sends a message.''' event_url = msg.get('event_url') msg = message_from_api(self.id, msg) msg = TransportUserMessage.send(**msg) msg = yield self._send_message(sender, outbounds, event_url, msg) returnValue(api_from_message(msg))
def send_reply_message(self, sender, outbounds, inbounds, msg): '''Sends a reply message.''' in_msg = yield inbounds.load_vumi_message(self.id, msg['reply_to']) if in_msg is None: raise MessageNotFound( "Inbound message with id %s not found" % (msg['reply_to'],)) event_url = msg.get('event_url') msg = message_from_api(self.id, msg) msg = in_msg.reply(**msg) msg = yield self._send_message(sender, outbounds, event_url, msg) returnValue(api_from_message(msg))
def test_message_from_api(self): msg = message_from_api( 'channel-id', { 'from': '+1234', 'content': None, 'channel_data': { 'continue_session': True, 'voice': {}, }, }) msg = TransportUserMessage.send(**msg) self.assertEqual(msg.get('continue_session'), True) self.assertEqual(msg.get('helper_metadata'), {'voice': {}}) self.assertEqual(msg.get('from_addr'), '+1234') self.assertEqual(msg.get('content'), None)
def test_message_from_api_reply(self): msg = message_from_api( 'channel-id', { 'reply_to': 1234, 'content': 'foo', 'channel_data': { 'continue_session': True, 'voice': {}, }, }) self.assertFalse('to_addr' in msg) self.assertFalse('from_addr' in msg) self.assertEqual(msg['continue_session'], True) self.assertEqual(msg['helper_metadata'], {'voice': {}}) self.assertEqual(msg['content'], 'foo')
def send_reply_message(self, sender, outbounds, inbounds, msg, allow_expired_replies=False): '''Sends a reply message.''' in_msg = yield inbounds.load_vumi_message(self.id, msg['reply_to']) # NOTE: If we have a `reply_to` that cannot be found but also are # given a `to` and the config says we can send expired # replies then pop the `reply_to` from the message # and handle it like a normal outbound message. if in_msg is None and msg.get('to') and allow_expired_replies: msg.pop('reply_to') returnValue((yield self.send_message(sender, outbounds, msg))) elif in_msg is None: raise MessageNotFound( "Inbound message with id %s not found" % (msg['reply_to'],)) vumi_msg = message_from_api(self.id, msg) vumi_msg = in_msg.reply(**vumi_msg) vumi_msg = yield self._send_message(sender, outbounds, vumi_msg, msg) returnValue(api_from_message(vumi_msg))
def send_reply_message(self, sender, outbounds, inbounds, msg, allow_expired_replies=False): '''Sends a reply message.''' in_msg = yield inbounds.load_vumi_message(self.id, msg['reply_to']) # NOTE: If we have a `reply_to` that cannot be found but also are # given a `to` and the config says we can send expired # replies then pop the `reply_to` from the message # and handle it like a normal outbound message. if in_msg is None and msg.get('to') and allow_expired_replies: msg.pop('reply_to') returnValue((yield self.send_message(sender, outbounds, msg))) elif in_msg is None: raise MessageNotFound("Inbound message with id %s not found" % (msg['reply_to'], )) vumi_msg = message_from_api(self.id, msg) vumi_msg = in_msg.reply(**vumi_msg) vumi_msg = yield self._send_message(sender, outbounds, vumi_msg, msg) returnValue(api_from_message(vumi_msg))
def send_message(self, sender, outbounds, msg): '''Sends a message.''' vumi_msg = message_from_api(self.id, msg) vumi_msg = TransportUserMessage.send(**vumi_msg) vumi_msg = yield self._send_message(sender, outbounds, vumi_msg, msg) returnValue(api_from_message(vumi_msg))