python - 如何将 Python 与 Dialogflow 聊天机器人连接

标签 python firebase firebase-authentication pycharm dialogflow-es

我已经在 Dialogflow 中创建了一个聊天机器人,我现在想使用 Pycharm 将其实现到我自己的 Python 环境中。我必须采取哪些剩余步骤来连接两者,以便我能够通过 Python 根据用户输入触发 Dialogflow 意图?我在下面的代码中测试了 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()

我的印象是 adminSDK .json 文件就是我必须实现的全部。 进一步阅读Here让我相信我需要设置身份验证,因此将其添加到上面的代码中:

#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)

不过,除了“进程完成”之外什么也没有显示。从这里开始,有什么方法可以检查我的平台是否可以与我的机器人进行通信,即接受用户输入并有目的地响应。

最佳答案

已解决

我还必须启动 GOOGLE_APPLICATION_CREDENTIALS,这使我能够从 Dialogflow 集成我的机器人。

关于python - 如何将 Python 与 Dialogflow 聊天机器人连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51584257/

相关文章:

python - 使用信号量限制并发 AsyncIO 任务数量不起作用

Python打包麻烦(ppt) : Getting error when trying to run my packaged project that uses a non-. 命令行下的py文件

firebase - 如何从Firebase DB检索子数据的值?

android - 在 Kotlin 中处理推送通知

android - 如果我在Firebase身份验证中使用Facebook登录,为什么我的currentUser始终为null?

python - 使用 heapify 与 heappush 创建堆。哪个更快?

python - 在使用groupby和transform进行计算时,如何仅在第一次出现时获得聚合结果,而在其他情况下获得0?

Firebase 错误 : Authentication required with firebase-tools

javascript - 使用 express nodejs 获取此错误 auth/operation-not-supported-in-this-environment

reactjs - Firebase 身份验证和 React Hook - 从钩子(Hook)返回的函数不起作用