我已经创建了一个使用dialogflow-fillfillment的webhook,以根据平台正确返回不同的数据,包括我为其他服务创建的自定义数据。我已经测试过Webhook,并且知道如果将其更改为originalDetectIntentRequest.source自定义有效负载中使用的平台,它将可以正常工作。
{
"payload": {
"jokes-api": {
"success": true,
"text": "These are some jokes",
}
},
"outputContexts": []
}
Run Code Online (Sandbox Code Playgroud)
我能够使用dialogflow-的NodeJS客户端-V2的sessions.detectIntent得到响应,但fullfilment回来与平台设置为PLATFORM_UNSPECIFIED,而不是定制的有效载荷我想要的。
[{
"responseId": "c56c462f-bb3b-434a-b318-3739f58e6f6d",
"queryResult": {
"fulfillmentMessages": [{
"platform": "PLATFORM_UNSPECIFIED",
"card": {
"buttons": [],
"title": "Jokes",
"subtitle": "These are some jokes",
"imageUri": ""
},
"message": "card"
}],
"queryText": "tell me a joke",
/* ... */
"intent": {
"name": "projects/my-jokes/agent/intents/56887375-3047-4993-8e14-53b20dd02697",
"displayName": "Jokes",
/* ... */
},
"intentDetectionConfidence": 0.8999999761581421,
}
}]
Run Code Online (Sandbox Code Playgroud)
查看我的Webhook日志,可以看到存在该originalDetectIntentRequest对象,但未设置源。 …
我正在为 Nodejs使用Dialogflow API。
这个 API 显然是由 Google 通过协议缓冲区实现的,尽管它提供了一个简单的基于 JavaScript/JSON 的接口,我已经成功地将它用于简单的查询。
为了请求 Dialogflow 向我发送特定平台的响应数据,我显然需要将一个简单的 JSON 对象编码为 protobuf 格式。链接的源代码给出了一个使用“structjson util”的示例,该示例可能用于进行必要的转换:
const structjson = require('./structjson.js');
const request = {
/* other properties omitted */
queryParams: {
payload: structjson.jsonToStructProto({source: 'ACTIONS_ON_GOOGLE'})
},
};
Run Code Online (Sandbox Code Playgroud)
不幸的是,为 structjson util 提供的链接已失效,我找不到其他对它的引用。
除了编码一个简单的 JSON 对象外,我不需要做任何事情,就像上面的例子一样。是否有一个简单的实用程序(运行时或命令行)可以用来做到这一点,而无需对 protobuf 工具链进行大手术?