python - 如何将 Python 与 Dialogflow 聊天机器人连接起来
问题描述
我在 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 文件就是我必须实现的全部。进一步阅读这里让我相信我需要设置身份验证,所以这被添加到上面的代码中:
#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 集成我的机器人。
推荐阅读
- c# - 没有为类型“Microsoft.AspNetCore.Mvc.ApiExplorer”找到可访问的构造函数
- angular - Angular 8 - 如何使用 ngxbootstrap/datepicker 仅显示日期和月份
- ionic-framework - ionic 6 websocket客户端cordova插件
- ios - Paypal Native Checkout SDK 抛出错误 - 在 Swift 5 中“无法加载模块 'PayPalCheckout”
- google-bigquery - 如何禁用 Google Big Query 中的预览功能?
- reactjs - 在 Heroku 上构建 Parcel React 应用程序失败
- ios - AVAudioPlayer 播放断断续续且无限?
- pos - 发布 DUKPT 密钥管理时 TermApp Postillion 上的 PIN 转换错误
- rspec - Rspec使用具有`before_validation`回调的范围验证唯一性
- boolean - 使用 9 位加法器进行 9 位减法