def test_response_serialization(self): response = TextMessage(text="Hello, world!") model = ChatMessage() model.response_dict = response assert isinstance(model.response, MessageElement) assert isinstance(model.serialized_response, dict) assert model.serialized_response[ '__type__'] == response.__module__ + "." + response.__class__.__name__
def send(self, conversation, responses, reply_to=None): """ Send responses to a conversation. :param conversation: a ChatConversation object :param responses: the messages we're sending, Iterable of MessageElement objects :param reply_to: (optional) message that we're replying to (used for example in Telegram) """ logging.info("Sending bot responses: %s", responses) conversation.interface.send_responses(conversation, reply_to, responses) for response in responses: message = ChatMessage() message.conversation = conversation message.user = reply_to.user if reply_to else None message.type = ChatMessage.MESSAGE message.text = response.get_text() message.time = timezone.now() message.is_user = False message.response_dict = todict(response) message.save()