def process_text(self, message_text): """ Understand text, process something and create response random text: outputs Default Options lyrics text (with previous Postback) : process request text """ (conversation, needs_follow_up, payload) = Conversation.get_last_message(self.conversation) Message.save_text(conversation, message_text) if needs_follow_up: if payload == "LYRICS_PAYLOAD": found_songs_data = MusixMatchAPI.search_lyrics(message_text) if len(found_songs_data) < 1: sorry_message = "Lo siento, No pudimos encontrar la canción :(" return (sorry_message, ResponseType.text) else: response_message = "Encontré {} canciones, espero esté la que buscabas".format( len(found_songs_data)) response_data = { "text": response_message, "data": found_songs_data, "buttons": { "title": "Favorita", "payload": "FAVORITE_{}_PAYLOAD", } } return (response_data, ResponseType.results) return (message_text, ResponseType.default)
def record_message_and_payload(self, message, payload, with_follow_up=False): """Save conversation Message and Mark message to followup """ conversation = Conversation.set_postback(self.conversation, payload) Message.save_text(conversation, message, with_follow_up=with_follow_up)