简体   繁体   中英

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. 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? I have tested a firestore query in the below code and it has successfully worked, so I know the AdminSDK is set up correctly.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM