I currently have a working ExpressJS webhook for api.ai hosted on EC2.
However, my backend fails when I use the identical GET/POST handlers in an https webhook. In particular, I don't see any (console.log) output from the POST handler, and my api.ai action returns a 206 error.
I've verified that the https webhook server is reachable from a browser. TIA for any suggestions
The api.ai JSON status is below:
{
"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"
}
The POST handler is below.
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}));
});