如何在发送到DialogFlow以前的Api.ai的请求JSON中添加额外字段

编程入门 行业动态 更新时间:2024-10-09 04:23:02
本文介绍了如何在发送到DialogFlow以前的Api.ai的请求JSON中添加额外字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将其他信息附加到json

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中添加额外字段

本文发布于:2023-11-28 04:52:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:发送到   字段   如何在   JSON   Api

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!