Exemplo n.º 1
0
def postback_handler(uid, postback):
    handlers = {
        'get_started': greetings,
        'base_query': base_query,
        'send_spotted': send_spotted,
        'ask_question': ask_question,
        'raw_solution_found': raw_solution_found,
        'raw_solution_not_found': raw_solution_not_found,
        'other': other
    }
    if not Chat.is_standby(uid):
        handlers[postback['payload']](uid)
Exemplo n.º 2
0
def postback_handler(uid, postback):
    handlers = {
        "get_started": greetings,
        "base_query": base_query,
        "send_spotted": send_spotted,
        "ask_question": ask_question,
        "raw_solution_found": raw_solution_found,
        "raw_solution_not_found": raw_solution_not_found,
        "other": other,
    }
    if not Chat.is_standby(uid):
        handlers[postback["payload"]](uid)
Exemplo n.º 3
0
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))()
Exemplo n.º 4
0
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))()
Exemplo n.º 5
0
def raw_solution_not_found(uid):
    message = "Então espera um pouco que alguém já vem te ajudar <3"
    Chat.set_raw_solution_not_found(uid)
    chain(simple_message.si(uid, message), pass_thread_control.si(uid))()
Exemplo n.º 6
0
def raw_solution_found(uid):
    message = "Foi um prazer ajudar!"
    Chat.set_raw_solution_found(uid)
    simple_message.delay(uid, message)
Exemplo n.º 7
0
def ask_question(uid):
    message = "Conta aí qual é a sua dúvida :)"
    simple_message.delay(uid, message)
    Chat.set_accept_raw(uid)
Exemplo n.º 8
0
def standby_handler(messages):
    for message in messages:
        # if it is a standby message with only postback, then it is that
        # nasty case where facebook echoes the bots postback messages even
        # when it has the control of the chat
        if message.get("postback",
                       False) and not message.get("message", False):
            # just ignore it
            continue

        sender = message["sender"]["id"]
        recipient = message["recipient"]["id"]
        is_echo = message["message"].get("is_echo", False)

        # If echo, the sender is the page
        if is_echo:
            # Reset standby counter
            Chat.set_standby(recipient)
            # append to log if log is enabled
            Chat.append_log(recipient, message["message"].get("text", ""),
                            True)
            continue

        # if chat is not standby(expired)
        if not Chat.is_standby(sender) and Chat.check_expired(sender):
            message_and_postback_and_handover_handler([message])
            continue

        # If the chat is on standby
        if Chat.is_standby(sender):
            # reset standby
            Chat.set_standby(sender)
            # append to log if log is enabled
            Chat.append_log(sender, message["message"].get("text", ""), False)
            continue
Exemplo n.º 9
0
def take_thread_control(uid):
    t = ThreadMessage(uid)
    t.send('take_thread_control')
    Chat.set_active(uid)
Exemplo n.º 10
0
def received_thread_control(uid):
    Chat.set_active(uid)
Exemplo n.º 11
0
def pass_thread_control(uid, target_id='263902037430900'):
    t = ThreadMessage(uid, target_id)
    t.send('pass_thread_control')
    Chat.set_standby(uid)
Exemplo n.º 12
0
def pass_thread_control(uid, target_id="263902037430900"):
    t = ThreadMessage(uid, target_id)
    t.send("pass_thread_control")
    Chat.set_standby(uid)