Example #1
0
def receive_message():
    if request.method == 'GET':
        """Before allowing people to message your bot, Facebook has implemented a verify token
        that confirms all requests that your bot receives came from Facebook."""
        token_sent = request.args.get("hub.verify_token")
        return verify_fb_token(token_sent)
    else:
        output = request.get_json()
        entry = output.get('entry')[0]
        messaging = entry.get('messaging')[0]
        sender = messaging.get('sender').get('id')
        id_sender = int(sender)

        if ID_BOT != id_sender:
            if 'message' in messaging:
                text = str(messaging.get('message').get("text", ""))

                if checkBase(id_sender):
                    if check('').getStep(id_sender).__eq__(step2):
                        print('Fazer Cadastro')
                        startStep(step2, id_sender, text)

                    elif check('').getStep(id_sender).__eq__(step3):
                        print('Valida Nome')
                        startStep(step3, id_sender, text)

                    elif check('').getStep(id_sender).__contains__('1.'):
                        if not check('').getStep(id_sender).__eq__('1.29'):
                            print('perguntas')
                            startStep(step4, id_sender, text)
                        else:
                            print('challenges p')

                    elif check('').getStep(id_sender).__eq__(step5):
                        print('Seq Pergunta')
                        startStep(step5, id_sender, text)

                    else:
                        print('challenges')

                else:
                    print('Primeira vez')
                    startStep(step1, id_sender, '')

            else:
                print("Sem Message")

    return "Message Processed"
Example #2
0
def getQuest(id, text):
    return "'" + check('').getQuestions(id) + ';' + text + "'"
Example #3
0
def checkQuestion(id, text):
    connec = conn(DATABASE)
    if check('').getStep(id).__eq__('1.1'):
        quest = "'" + text + "'"
        connec.updateQuestions(TABLE, id, quest)
        connec.updateStep(TABLE, id, '1.2')
        send_message(id, list_questions.get(str(int(check('').getStep(id)[2:]))))

    elif check('').getStep(id).__eq__('1.2'):
        connec.updateQuestions(TABLE, id, getQuest(id, text))
        connec.updateStep(TABLE, id, getNextQuestion(id))
        send_message(id, '\'S\' para Sim, \'N\' para Não ou \'A\' para As vezes')
        send_message(id, list_questions.get(str(int(check('').getStep(id)[2:]))))

    elif check('').getStep(id).__eq__('1.18'):
        connec.updateQuestions(TABLE, id, getQuest(id, text))
        connec.updateStep(TABLE, id, getNextQuestion(id))
        send_message(id, list_questions.get(str(int(check('').getStep(id)[2:]))))

    elif check('').getStep(id).__eq__('1.28'):
        connec.updateQuestions(TABLE, id, getQuest(id, text))
        connec.updateStep(TABLE, id, getNextQuestion(id))
        send_message(id, 'Obrigado Por responder o questionario!')
        send_message(id, 'Caso tenha alguma dúvida deseja indicar alguma melhoria, ou queira fazer alguma alteração dos seus dados, por favor entre em contato no e-mail: [email protected]')
        send_message(id, 'Iremos analisar as respostas enviadas e entraremos em contato em breve!')

    else:
        if text.upper().__eq__('S'):
            connec.updateQuestions(TABLE, id, getQuest(id, text))
            connec.updateStep(TABLE, id, getNextQuestion(id))
            send_message(id, list_questions.get(str(int(check('').getStep(id)[2:]))))
        elif text.upper().__eq__('N'):
            connec.updateQuestions(TABLE, id, getQuest(id, text))
            connec.updateStep(TABLE, id, getNextQuestion(id))
            send_message(id, list_questions.get(str(int(check('').getStep(id)[2:]))))
        elif text.upper().__eq__('A'):
            connec.updateQuestions(TABLE, id, getQuest(id, text))
            connec.updateStep(TABLE, id, getNextQuestion(id))
            send_message(id, list_questions.get(str(int(check('').getStep(id)[2:]))))
        else:
            send_message(id, 'Opcao invalida, tente novamente!')
            send_message(id, '\'S\' para Sim, \'N\' para Não ou \'A\' para As vezes')
            send_message(id, list_questions.get(str(int(check('').getStep(id)[2:]))))
Example #4
0
def getNextQuestion(id):
    next = '1.' + str(float(check('').getStep(id)[2:]) + 1).replace('.0','')
    return "'"+next+"'"
Example #5
0
def checkBase(id):
    return check('').checkExist(id)