简体   繁体   English

使用 python 后端脚本操作现有的 Dialogflow CX session

[英]manipulate an existing Dialogflow CX session with a python backend script

I have an existing and functional Chat Bot with Google Dialogflow CX.我有一个现有的功能聊天机器人与 Google Dialogflow CX。 The Chatbot is directly integrated in a website by the Google Bootstrap. Chatbot 通过 Google Bootstrap 直接集成到网站中。

In some cases a Python script must trigger an intent or page for the user from the backend.在某些情况下,Python 脚本必须从后端为用户触发意图或页面。 In that case the user (and his client) should directly jump in this intent.在那种情况下,用户(和他的客户)应该直接跳入这个意图。 The session ID of the user is known.用户的 session ID 已知。

So far I managed it to set a parameter for the user from the python script using the following code.到目前为止,我设法使用以下代码从 python 脚本为用户设置参数。

from google.cloud import dialogflowcx_v3beta1 as dialogflow
from google.cloud.dialogflowcx_v3beta1 import types

session_id = "7826e7-0b7-794-b24-b95271869"

api_endpoint = f"{location_id}-dialogflow.googleapis.com"
client_options = {"api_endpoint": api_endpoint}
client = dialogflow.services.sessions.SessionsClient(client_options=client_options)

event = "live_chat_event"
params = {'message': "Hello World"}

event_input = types.EventInput(event=event)
query_input = types.QueryInput(event=event_input, language_code=language_code)
query_params = types.QueryParameters(parameters=params)

request = types.DetectIntentRequest(
        session=session_path,
        query_input=query_input,
        query_params = query_params
        )
response = client.detect_intent(request=request)

print(response.query_result.response_messages[0])

These parameters are then visible by the user on his client, but only after typing the next message.然后,用户在其客户端上可以看到这些参数,但只能在键入下一条消息后才能看到。

I need the client to refresh itself or let it jump directly into the next page without any additional input from the user.我需要客户端自行刷新或让它直接跳转到下一页,而无需用户进行任何额外输入。

How can that be achieved?如何实现?

Hey bro don't get complicated.嘿,兄弟,别复杂了。

If you are struggling to get the DF API to work you are not the only one.如果您正在努力让 DF API 正常工作,那么您不是唯一一个。

I can advise you to try the Voximplant Python Client so you can connect to your DF CX Agent easily and control that script.我可以建议您尝试 Voximplant Python 客户端,这样您就可以轻松连接到您的 DF CX 代理并控制该脚本。 On top of that you can also handle calls with your DF CX or ES Agent.除此之外,您还可以使用 DF CX 或 ES 代理处理呼叫。

You can check the documentation to add teh Credentials for DF here .您可以在此处查看文档以添加 DF 的凭据。

Also please check this Python API Client so you can run a Scenario that communicates with your CX Agent.另请检查此Python API 客户端,以便您可以运行与 CX 代理通信的场景

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

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