简体   繁体   English

如何在 javascript 代码中触发对话流意图?

[英]How can I trigger a dialogflow intent inside a javascript code?

I have a chatbot using dialogflow agent.我有一个使用 dialogflow 代理的聊天机器人。 I wrote a javascript back end code for its webhook fulfillment.我为它的 webhook 实现编写了一个 javascript 后端代码。 I checked some condition in this code and if the condition is true I want a special intent to be triggered.我检查了这段代码中的一些条件,如果条件为真,我希望触发一个特殊的意图。 How can I do this?我该怎么做? What is the correct java script code to triggered an intent inside a java script if statement?在 java 脚本 if 语句中触发意图的正确 java 脚本代码是什么?

What function do you intend to perform by triggering an intent?您打算通过触发意图来执行什么功能? Diaglogflow has v1 & v2 API references for this. Diaglogflow 对此有v1 & v2 API references You can do GET/POST/PUT/DELETE operations by triggering an intent using ajax call in your javascript code.您可以通过在 JavaScript 代码中使用 ajax 调用触发意图来执行GET/POST/PUT/DELETE操作。 Please read more about this here https://dialogflow.com/docs/reference/agent/intents请在此处阅读更多相关信息https://dialogflow.com/docs/reference/agent/intents

To make things clearer, DialogFlow intents are triggered by querying using the query API ( https://dialogflow.com/docs/reference/agent/query )为了使事情更清楚,DialogFlow 意图是通过使用查询 API ( https://dialogflow.com/docs/reference/agent/query ) 进行查询来触发的

Note: V1 of the DialogFlow API will deprecate soon, and will be replaced by V2 which is using gRPC.注意:DialogFlow API 的 V1 即将弃用,并将被使用 gRPC 的 V2 取代。

This means that if you wish to trigger the intent programmatically and have the fulfilment triggered as well, you should have the following:这意味着,如果您希望以编程方式触发意图并同时触发履行,您应该具备以下条件:

  1. Script (can be on JavaScript as you would like to) with REST API request (doable using the Axios library) to the DialogFlow Query API.使用 REST API 请求(可使用Axios库)到 DialogFlow 查询 API 的脚本(可以根据需要使用 JavaScript)。

  2. DialogFlow will pick up the query, runs it through and triggers the Intent (if the query matches the intent). DialogFlow 将接收查询,运行它并触发意图(如果查询匹配意图)。

  3. In processing the intent, because there is a fulfilment, DialogFlow will run the fulfilment, which is another API/webhook call to your server hosted somewhere.在处理意图时,因为有履行,DialogFlow 将运行履行,这是对托管在某处的服务器的另一个 API/webhook 调用。

  4. Your server will pick up the API request, and process accordingly.您的服务器将接收 API 请求,并进行相应处理。

Try out the Query API from DialogFlow and see if it works out for you.试用 DialogFlow 的 Query API,看看它是否适合您。

Okay, I am late here, but I have used the below approach to encounter such a situation.好吧,我来晚了,但我使用以下方法遇到了这种情况。 You can use custom event and intent chaining .您可以使用自定义事件意图链接

I followed the below URL and implemented the same.我按照下面的 URL 并实现了相同的。 Maybe this help someone.也许这可以帮助某人。

enter link description here在此处输入链接描述

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

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