node.js - 使用 http.get 时必须设置 final_response
问题描述
我尝试使用 dialogflow 和 webhook。Everythink 工作,直到我添加一个 http 请求。我有以下错误:
必须设置 MalformedResponse 'final_response'。
这是我的代码:
function askMovie (response) {
return new Promise((resolve, reject) => {
// resolve("THIS ONE WORKS if I comment the http.get");
http.get('http://www.omdbapi.com/?apikey=[MY_HIDDEN_API_KEY]&s=lego', res => {
let raw = '';
res.on('data', chunk => raw += chunk);
res.on('end', () => {
resolve("OK");
});
res.on('error', (error) => {
reject(error);
});
});
});
}
exports.dialogflowWebhook = functions.https.onRequest((request, response) => {
askMovie(response).then((output) =>{
response.json({ fulfillmentText: 'Request Success' });
}).catch((error) => {
response.json({ fulfillmentText: 'No movies' });
})
});
我尝试了其他样本,但总是同样的错误。
失败时的响应:
{
"responseMetadata": {
"status": {
"code": 10,
"message": "Failed to parse Dialogflow response into AppResponse because of empty speech response",
"details": [
{
"@type": "type.googleapis.com/google.protobuf.Value",
"value": "{\"id\":\"fdcfc60e-8da3-42cc-84a8-a5de5f4accf8\",\"timestamp\":\"2018-05-03T13:46:26.646Z\",\"lang\":\"fr-fr\",\"result\":{},\"status\":{\"code\":206,\"errorType\":\"partial_content\",\"errorDetails\":\"Webhook call failed. Error: 500 Internal Server Error\"},\"sessionId\":\"1525354490725\"}"
}
]
}
}
}
我为我的 webhook 使用了 firebase 函数。
解决方案
您缺少“fulfillment.speech” Json 元素。在您的服务器日志上验证这一点。需要默认语音响应。
"fulfillment": {
"speech": "Nice to meet you, Sam!"
},
https://developers.google.com/actions/reference/v1/dialogflow-webhook
推荐阅读
- reactjs - 我的 api 函数在另一个文件或目录中我想在 react native 的另一个文件或目录中检查我的 api 响应数据
- python-3.x - 从顺序 API 模型转换为功能 API 模型
- javascript - 如何从本地存储项创建单独的列表项并将它们显示在待办事项列表中?
- flutter - 在 listView 中给出特定数字时出错
- python - 手动将 Python 移动到其他驱动器后卸载 Python
- c - 修改字符串并返回修改后的字符串的函数
- javascript - StartsWith 函数不起作用,为什么?JavaScript
- dataframe - 应用于数据框中空数组列的大小函数在溢出后返回 1
- javascript - 从映射函数 React 返回空对象
- javascript - 在 2 个数组中找到交集的最佳方法是什么?每种方法的算法复杂度是多少?