def message_handler(uid, message): if Chat.is_standby(uid): # Ignore if, the user is standby return if not Chat.is_accepting_raw(uid): # If not accepting raw, return base return base_query(uid) # Set last sent raw message Chat.set_last_raw_message(uid, message['text']) # Process raw message response = api_process_raw_bot_message(message['text']) result = response['result'] result_status = response['result_status'] if result_status: # Some response was found buttons = [{ 'type': 'postback', 'title': 'Era isso :)', 'payload': 'raw_solution_found' }, { 'type': 'postback', 'title': 'Não ajudou :(', 'payload': 'raw_solution_not_found' }] payload = { 'template_type': 'button', 'text': result, 'buttons': buttons } return template_message.delay(uid, payload) # If no response was found, handover to human Chat.set_raw_solution_not_found(uid) message = 'Boa pergunta :p\nVou consultar os universitários e já volto' chain(simple_message.si(uid, message), pass_thread_control.si(uid))()
def message_handler(uid, message): if Chat.is_standby(uid): # Ignore if, the user is standby return if not Chat.is_accepting_raw(uid): # If not accepting raw, return base return base_query(uid) # Set last sent raw message Chat.set_last_raw_message(uid, message["text"]) # Process raw message response = api_process_raw_bot_message(message["text"]) result = response["result"] result_status = response["result_status"] if result_status: # Some response was found buttons = [ { "type": "postback", "title": "Era isso :)", "payload": "raw_solution_found", }, { "type": "postback", "title": "Não ajudou :(", "payload": "raw_solution_not_found", }, ] payload = {"template_type": "button", "text": result, "buttons": buttons} return template_message.delay(uid, payload) # If no response was found, handover to human Chat.set_raw_solution_not_found(uid) message = "Boa pergunta :p\nVou consultar os universitários e já volto" chain(simple_message.si(uid, message), pass_thread_control.si(uid))()