dialogflow-es - 格式错误的响应:由于语音响应为空,无法将 Dialogflow 响应解析为 AppResponse
问题描述
我在 Dialogflow 中使用 firebase 函数来实现 webhook。我正在使 webhook 成功,fulfillment status
但它不起作用。我使用的是版本 1。当我在 Google Assistant 模拟器上对其进行测试时,它显示“应用程序没有响应”。
火力基地功能
const functions = require('firebase-functions');
exports.webhook = functions.https.onRequest((request, response) => {
response.send({
"google":{
"richResponse":{
"items":[
{
"simpleResponse":{
"textToSpeech":"Hey! Good to see you."
}
},
{
"mediaResponse":{
"mediaType":"AUDIO",
"mediaObjects":[
{
"name":"Exercises",
"description":"ex",
"largeImage":{
"url":"http://res.freestockphotos.biz/pictures/17/17903-balloons-pv.jpg",
"accessibilityText":"..."
},
"contentUrl":"https://theislam360.me:8080/hbd.mp3"
}
]
}
}
],
"suggestions":[
{
"title":"chips"
}
]
}
}
}
)
});`
{google...
当我通过 GUI 手动将响应从自定义有效负载中复制粘贴到末尾时,它可以工作。而对于 webhook,它不起作用。
原始 API 响应
{
"id": "eaf627ed-26b5-4965-b0b0-bc77144e144b",
"timestamp": "2019-04-15T11:54:18.948Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "play hbd",
"action": "",
"actionIncomplete": false,
"parameters": {
"any": "hbd"
},
"contexts": [],
"metadata": {
"isFallbackIntent": "false",
"webhookResponseTime": 34,
"intentName": "play",
"intentId": "e60071cd-ce31-4ef9-ae9b-cc370c3362b3",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false"
},
"fulfillment": {
"messages": []
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "e91bd62f-766b-b19d-d37b-2917ac20caa6"
}
履行请求
{
"id": "eaf627ed-26b5-4965-b0b0-bc77144e144b",
"timestamp": "2019-04-15T11:54:18.948Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "play hbd",
"speech": "",
"action": "",
"actionIncomplete": false,
"parameters": {
"any": "hbd"
},
"contexts": [],
"metadata": {
"intentId": "e60071cd-ce31-4ef9-ae9b-cc370c3362b3",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"isFallbackIntent": "false",
"intentName": "play"
},
"fulfillment": {
"speech": "",
"messages": []
},
"score": 1
},
"status": {
"code": 200,
"errorType": "success"
},
"sessionId": "e91bd62f-766b-b19d-d37b-2917ac20caa6"
}
履行响应
{
"google": {
"richResponse": {
"items": [
{
"simpleResponse": {
"textToSpeech": "Hey! Good to see you."
}
},
{
"mediaResponse": {
"mediaType": "AUDIO",
"mediaObjects": [
{
"name": "Exercises",
"description": "ex",
"largeImage": {
"url": "http://res.freestockphotos.biz/pictures/17/17903-balloons-pv.jpg",
"accessibilityText": "..."
},
"contentUrl": "https://theislam360.me:8080/hbd.mp3"
}
]
}
}
],
"suggestions": [
{
"title": "chips"
}
]
}
}
}
履行状态
Webhook execution successful
解决方案
您没有在响应中使用正确的 JSON。通过将其放入 GUI 中的“自定义负载”部分,它会为您创建更大的 JSON 响应。该google
对象需要位于data
Dialogflow v1 或payload
Dialogflow v2 的对象下。(如果你还没有切换到 v2 - 你应该立即这样做,因为 v1 将在大约一个月后关闭。)
所以你返回的应该看起来更像
{
"payload": {
"google": {
...
}
}
}
推荐阅读
- r - 在包含单个双引号的列上使用 data.table::fread
- c++ - 调用 `curl_easy_send` 和 `curl_easy_recv` 时应用了哪些 `libcurl` 选项?
- excel - 如何将Bloomberg函数BDP“植入”到单元格VBA中
- apache-spark - Spark 2.x - parquet 文件的 gzip 与 snappy 压缩
- java - 使用 Java api 查找索引是否存在的弹性搜索
- javascript - Jquery UI Draggable溢出问题
- java - 每个连接的 Java asyncHttpClient 新线程
- java - Java 流无干扰和副作用
- c++ - 在 C++ 中更改跟踪器的 fps
- github - 没有批准按钮的 GitHub ssh 密钥审核