我尝试使用dialogflow和webhook。在我添加 http 请求之前,一切都有效。我有以下错误:
必须设置格式错误的响应"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"}"
}
]
}
}
}
我使用Firebase函数来制作我的网络钩子。
你错过了你的"fulfillment.speech"Json元素。 在服务器日志中验证这一点。 默认语音响应是必需的。
"fulfillment": {
"speech": "Nice to meet you, Sam!"
},
https://developers.google.com/actions/reference/v1/dialogflow-webhook