我正在尝试将其他信息附加到json 从我的应用程序发送到DialogFlow的请求.我知道有可能通过触发在查询请求中发送参数,而我已经将该方法用于其他功能.
I am trying to append extra information to the jsonrequest that is sent from my application to DialogFlow. I am aware of the possibility to send data calling an intent by triggering its event from Sending Parameters in a Query Request, and I am using that method already for other functionality.
基本上,我试图在userID中添加一个值,我需要在DialogFlow中检索该值.我在 php 的问题中跟踪会话,因此我正在使用 php 的问题来获取ID值.我已尝试在 ajax 请求:
Basically, I am trying to add a value with the userID, and I need to retrieve that value in DialogFlow. I am keepeing track of the session in php, so I am using phpto get ID value. I have tried to do the following in the ajaxrequest:
$.ajax({ type: "POST", url: baseUrl + "query?v=20150910", contentType: "application/json; charset=utf-8", dataType: "json", headers: { "Authorization": "Bearer " + accessToken }, //This folllowing line is the modified part: data: JSON.stringify({ query: text, lang: "en", sessionId: "somerandomthing", userId: "100" }), success: function(data) { }, error: function() { setResponse("Internal Server Error"); } });这也是:
$.ajax({ type: "POST", url: baseUrl + "query?v=20150910", contentType: "application/json; charset=utf-8", dataType: "json", headers: { "Authorization": "Bearer " + accessToken }, //This folllowing line is the modified part: data: JSON.stringify({ query: text, lang: "en", sessionId: "somerandomthing", userId: "100", parameters: { userId: "100" } }), success: function(data) { }, error: function() { setResponse("Internal Server Error"); } });我需要在请求中使用该值来基于它处理back-end中的某些数据.如果有人知道该怎么做,或者有更好的方法的建议,将不胜感激.
I need that value in the request to process some data in the back-end based on it. If anyone knows how to do it, or has suggestions for a better approach that would be much appreciated.
在DialogFlow论坛中有与此相关的讨论帖子,但仍然没有解决方案.该功能可能不可用,或没有记录在链接1 ,链接2 ,链接3 .
There are discussion posts related to this in the DialogFlow Forums, but there is still no resolution. The feature might not be available, or it is not documented Link 1, Link 2, Link 3.
推荐答案我在Dialogflow的@Svetlana的帮助下解决了此问题.原始帖子为这里,下面是一个带有Node.js后端的JavaScript应用程序的示例:
I solved this issue with the help of @Svetlana from Dialogflow. The original post is Here, and here is an example from a JavaScript application with back-end in Node.js:
您可以将请求的格式设置为:
You would format your request like:
$.ajax({ type: "POST", url: baseUrl + "query?v=20150910", contentType: "application/json; charset=utf-8", dataType: "json", headers: { "Authorization": "Bearer " + accessToken }, data: JSON.stringify({originalRequest: {data: {exampleMessage: 'Test'}}, query: text, lang: 'en', sessionId: 'somerandomthing'}), success: function (data) { }, error: function () { setResponse("Internal Server Error"); } });,您将使用以下命令访问Webhook中的值:
and you would access the value in the webhook with:
var exampleMessage = req.body.originalRequest.data.exampleMessage;或
var exampleMessage = req.body.originalRequest.data['exampleMessage'];希望这会有所帮助.
更多推荐
如何在发送到DialogFlow以前的Api.ai的请求JSON中添加额外字段
发布评论