Search code examples
node.jsgoogle-homeapi-ai

api.ai webhook not working on heroku, error 206 partial content


I'm trying to just get the basic node.js webhook echo example working on heroku. However I keep getting 206 errors. I've heard this can be from redirects that heroku does or from incomplete json. Any help here?

I also attached my intents screenshot on api.ai

enter image description here

I get this same error with the yahoo weather sample python app, so i'm not sure whats going on, as that is all api.ai configuration.

and i asked the question here as well https://discuss.api.ai/t/webhook-issue-error-206/4535/4

my code is as follows, i'm new to node.js, is something wrong? I added fields for what i thought api.ai needs in its JSON.

app.post('/hook', function(req, res) {
console.log('hook request');

try {
    var speech = 'empty';
    if (req.body) {
        if (req.body.result) {
            speech = '';

            if (req.body.result.fulfillment) {
                speech += req.body.result.fulfillment.speech;
                speech += ' ';
            }

            if (req.body.result.action) {
                speech += 'action: ' + req.body.result.action;
            }
        }
    }

console.log('result: ', speech);

return res.json({
    speech: speech,
    displayText: speech,
    data: [],
    contextOut: [],
    source: 'yahooweather'
});

Solution

  • I wish I could ask you in a comment how are you putting the webhook url in the api.ai fulfillment, but I don't have enough reputation for that :(

    By the message you are getting in heroku: at=info method=POST path="/" host=car-status.herokuapp.com request_id=b08633f7-33ab-45f3-9493-91be258a2b52 fwd="54.157.251.180" dyno=web.1 connect=0ms service=25ms status=404 bytes=376 I would guess you are using just the host url, without putting /hook in the end. See path="/" and status=404 (not found). In your code, you don't have an entry to the / path, only /hook, so that would be a reason to get a 404.