Exemplo n.º 1
0
def test_create_context(capsys):
    # Calling detect intent to create a session.
    detect_intent_texts.detect_intent_texts(PROJECT_ID, SESSION_ID, ['hi'],
                                            'en-US')

    context_management.create_context(PROJECT_ID, SESSION_ID, CONTEXT_ID, 1)
    context_management.list_contexts(PROJECT_ID, SESSION_ID)

    out, _ = capsys.readouterr()
    assert CONTEXT_ID in out
Exemplo n.º 2
0
def reply_from_dialogflow(update: Update, context: CallbackContext) -> None:
    project_id = os.getenv("DIALOGFLOW_PROJECT_ID")
    language_code = os.getenv("LANGUAGE_CODE")
    session_id = f'tg-{update.effective_user.id}'
    texts = update.message.text
    response = detect_intent_texts(
        project_id, session_id, texts, language_code)
    update.message.reply_text(response.query_result.fulfillment_text)
Exemplo n.º 3
0
def reply_from_dialogflow(event, vk_api):
    project_id = os.getenv("DIALOGFLOW_PROJECT_ID")
    language_code = os.getenv("LANGUAGE_CODE")
    session_id = f'vk-{event.user_id}'
    response = detect_intent_texts(project_id, session_id, event.text,
                                   language_code)
    if not response.query_result.intent.is_fallback:
        vk_api.messages.send(user_id=event.user_id,
                             message=response.query_result.fulfillment_text,
                             random_id=random.randint(1, 1000))
Exemplo n.º 4
0
def run_process(data):
    if (data['channel'] == "facebookMessenger"):

        #send to dialogflow
        output_dialogflow = detect_intent_texts("chatbotapiintegration-hvlbfm",
                                                "whatsapp:+34619316053",
                                                [data['text']],
                                                DIALOGFLOW_LENGUAGE)
        #send to facebook messenger the response
        send_facebookmessage(data['from'],
                             output_dialogflow['fulfillment_text'])
        channelColor = "green"

    elif (data['channel'] == "twillio"):
        #send to dialogflow
        output_dialogflow = detect_intent_texts("chatbotapiintegration-hvlbfm",
                                                data['from'], [data['text']],
                                                DIALOGFLOW_LENGUAGE)

        #if end process, send the media file
        media_url = ''
        if (output_dialogflow['action'] == 'room.reservation.yes'):
            media_url = 'http://fireworks.my/v4/wp-content/uploads/2017/08/Untitled6.jpg'
        #send to Whatsapp the response
        send_WhatsApp(data['from'], data['to'],
                      output_dialogflow['fulfillment_text'], media_url)
        channelColor = "red"

    #Envia Pregunta y Respuesta a Salesforce
    text1 = '<p style="color:' + channelColor + ';" align="left">' + 'Lead(' + data[
        'from'] + '): ' + data['text'] + '</p>'
    text2 = '<p style="color:blue;" align="right">' + 'Chatbot: ' + output_dialogflow[
        'fulfillment_text'] + '</p>'
    authtoken = salesforce_Autentication()
    result = salesforce_LiveChatTranscript(
        text1 + text2, data['from'].replace('whatsapp:+34', ''), authtoken)
    print('Resultado: ' + result)

    print(json.dumps(data))
    return "ok"
Exemplo n.º 5
0
def generate_intermediate_code():
    lines = DB_Manager.get_pseudocode_from_db()[0]
    full_pc = ""
    for line in lines:
        pc = detect_intent_texts(PROJECT_ID, SESSION_ID, [line], 'en-US')
        full_pc = full_pc + '\n' + pc

    print(full_pc)
    # f = open(os.path.join(app.config['DOWNLOAD_FOLDER']) + '/ipc.txt', "w+")
    f = open("ipc.txt", "w+")
    f.write(full_pc)
    DB_Manager.delete_all_documents("pseudocodes_temp")
    # path = "ipc.txt"
    # return send_file(path, as_attachment=True)
    return render_template('result1.html', statements=lines)
Exemplo n.º 6
0
def test_detect_intent_texts(capsys):
    detect_intent_texts(AGENT, SESSION_ID, TEXTS, "en-US")
    out, _ = capsys.readouterr()

    assert "Response text: I can help you find a ticket" in out
def test_detect_intent_texts(capsys):
    detect_intent_texts(PROJECT_ID, SESSION_ID, TEXTS, "en-US")
    out, _ = capsys.readouterr()

    assert "Fulfillment text: All set!" in out
def test_detect_intent_texts(capsys):
    detect_intent_texts(PROJECT_ID, SESSION_ID, TEXTS, 'en-US')
    out, _ = capsys.readouterr()

    assert 'Fulfillment text: All set!' in out
Exemplo n.º 9
0
def test_detect_intent_texts():
    detect_intent_texts(PROJECT_ID, SESSION_ID, lines, 'en-US')
Exemplo n.º 10
0
def send_message():
    message = "Hi, Name please"
    project_id = os.getenv('DIALOGFLOW_PROJECT_ID')
    fulfillment_text = detect_intent_texts(project_id, "unique", message, 'en')
    response_text = {"message": fulfillment_text}
    print(response_text)
Exemplo n.º 11
0
def test_detect_intent_texts():
    for line in lines:
        detect_intent_texts(PROJECT_ID, SESSION_ID, line, 'en-US')