简体   繁体   English

如何将 Python 与 Dialogflow 聊天机器人连接起来

[英]How to connect Python with Dialogflow Chatbot

I have created a chatbot in Dialogflow, I want to now implement this into my own Python environment with Pycharm.我在 Dialogflow 中创建了一个聊天机器人,现在我想用 Pycharm 将它实现到我自己的 Python 环境中。 What remaining steps must I take to connect the two so I am in a position to trigger Dialogflow intents based on user inputs, all through Python?我必须采取哪些剩余步骤才能将两者连接起来,以便我能够通过 Python 根据用户输入触发 Dialogflow 意图? I have tested a firestore query in the below code and it has successfully worked, so I know the AdminSDK is set up correctly.我已经在下面的代码中测试了一个 firestore 查询,它已经成功运行,所以我知道 AdminSDK 设置正确。

import os
import json
import sys
import dialogflow
from dialogflow_v2beta1 import *
import firebase_admin
from firebase_admin import firestore
from firebase_admin import credentials
import requests.packages.urllib3
requests.packages.urllib3.disable_warnings()
import Tkinter
from Tkinter import *

#Initialize the firebase admin SDK
cred = credentials.Certificate('./mycredfile.json')
default_app = firebase_admin.initialize_app(cred)
db = firestore.client()

#halfcoded gui in chatbot format, to later publish in html and allow user to acess

#window = Tk()
#window.title("Chatbot")
#window.geometry('400x400')
#User_Input = Entry(window, width=50).place(x=20, y=350)
#subButton = Button(window, text="Send")
#subButton.place(x =350, y=350)
#window.mainloop()

I was under the impression the adminSDK .json file was all I had to implement.我的印象是 adminSDK .json 文件就是我必须实现的全部。 Further reading Here has lead me to believe I need to set up authentication, so this was added to the above code:进一步阅读这里让我相信我需要设置身份验证,所以这被添加到上面的代码中:

#Connect to Dialogflow using Service Account Credential
def explicit():
    from google.cloud import storage

    # Explicitly use service account credentials by specifying the private key file.

    storage_client = storage.Client.from_service_account_json(
        './chatbot-pvtkeyfile.json')
    # Make an authenticated API request
    buckets = list(storage_client.list_buckets())
    print(buckets)

Though, nothing but "process finished" shows.虽然,只有“过程完成”显示。 From here, are there any ways to check if my platform can communicate with my bot, ie, take user input and respond with an intent.从这里开始,是否有任何方法可以检查我的平台是否可以与我的机器人通信,即接受用户输入并根据意图进行响应。

SOLVED解决了

I had to also initiate the GOOGLE_APPLICATION_CREDENTIALS, which enabled me to integrate my bot from Dialogflow.我还必须启动 GOOGLE_APPLICATION_CREDENTIALS,这使我能够从 Dialogflow 集成我的机器人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何连接Python chatbot和Java chat room - How to connect Python chatbot and Java chat room 如何使用python在Messenger-Dialogflow聊天机器人中将Mysql查询结果作为Excel报告发送 - How to send a Mysql query result as Excel report in Messenger-Dialogflow chatbot using python 如何将RasaCore Chatbot连接到Messenger? - How to connect RasaCore Chatbot to Messenger? 如何安装/使用Python ChatBot? - How to install/use Python ChatBot? 如何通过python sdk或javascript将我的chatbot用户界面连接到APIAI serverhost? - how to connect my chatbot user interface to APIAI serverhost via python sdk or javascript? 使用Python通过Cloudfunctions将Dialogflow与Google BigQuery连接 - Connect Dialogflow with Google BigQuery via Cloudfunctions with Python 如何在 Python 中使用 dialogflow 客户端 - How to use dialogflow Client In Python 如何将Dialogflow与Django(Python)集成? - How to integrate Dialogflow with Django (Python)? 如何使用dialogflow从flask webhook向facebook聊天机器人发送多个回复? - How to send multiple replies from flask webhook to facebook chatbot using dialogflow? 如何用 Python 回复未知 ChatBot Telegram 中的消息? - How to Reply Message in Unknown ChatBot Telegram with Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM