我目前在EC2上有一个用于api.ai的ExpressJS webhook。
然而,当我在https webhook中使用相同的GET / POST处理程序时,我的后端失败了。特别是,我没有看到POST处理程序的任何(console.log)输出,我的api.ai操作返回206错误。
我已经确认可以从浏览器访问https webhook服务器。任何建议的TIA
api.ai JSON状态如下:
{
"id": "ff86f1da-a136-4ec2-b7f8-4aa7cb443f5a",
"timestamp": "2017-07-16T19:04:27.522Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "add bread",
"action": "",
"actionIncomplete": false,
"parameters": {
"number": "",
"shopping_item": "bread",
"unit-weight-name": ""
},
"contexts": [],
"metadata": {
"intentId": "7ea8b3b1-28d6-418e-b9d2-b7353bf5a008",
"webhookUsed": "true",
"webhookForSlotFillingUsed": "false",
"webhookResponseTime": 126,
"intentName": "add shopping item"
},
"fulfillment": {
"speech": "done",
"messages": [
{
"type": 0,
"speech": "okey-dokey"
}
]
},
"score": 0.9599999785423279
},
"status": {
"code": 206,
"errorType": "partial_content",
"errorDetails": "Webhook call failed. Error: Webhook response was empty."
},
"sessionId": "963f3693-5fa3-4d45-a3f3-817f9d433965"
}
POST处理程序位于下方。
app.post('/',function(req, res){
res.setHeader('Content-Type', 'application/json');
//debugging output for the terminal
console.log('you posted: Id: ' + req.body.id + ', Item: ' + req.body.result.parameters.shopping_item
+ ', Query: '+req.body.result.resolvedQuery);
jsonObj={};
jsonObj["displayText"]=req.body.result.parameters.shopping_item;
jsonObj["textToSpeech"]=req.body.result.parameters.shopping_item;
jsonObj["formattedText"]=req.body.result.parameters.shopping_item;
response = "added - "+req.body.result.parameters.shopping_item;
res.send(JSON.stringify({ "speech": response, "displayText": response}));
});