2017-03-16 74 views
0

我想只获得基本的node.js webhook回声示例工作在heroku上。但是,我不断收到206错误。我听说这可能来自heroku做的重定向或不完整的json。这里有帮助吗?api.ai webhook不工作在heroku上,错误206部分内容

我也附上了我的意图截图上api.ai

enter image description here

我获得与雅虎天气Python应用程序同样的错误,所以我不知道怎么回事,因为这是所有api.ai配置。

,我在这里问的问题以及https://discuss.api.ai/t/webhook-issue-error-206/4535/4

我的代码如下,我是新来的node.js,有什么不妥?我添加了我认为api.ai在其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' 
}); 
+0

当api.ai尝试访问它时,这是paratrail在我的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 protocol = https' – MadeByDouglas

+0

这两个示例都不工作https://github.com/api-ai/apiai- webhook-sa​​mple和https://github.com/api-ai/apiai-webhook-sa​​mple – MadeByDouglas

回答

2

我希望我能问你在评论你是如何把网络挂接网址在api.ai履行,但我没有足够的信誉为保证:(

由消息您越来越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我猜您只使用主机URL,没有把/hook到底 见path="/"status=404(未找到) 在你的代码,你没有给/路径条目,只有/hook,所以这将是获得404的理由。

+0

是的,这就是它!我实际上已经知道了,忘了更新这个SO。我忘了添加/钩子 – MadeByDouglas

+0

它是令人困惑的,因为它似乎有其他人得到错误的原因完全不同,所以它把我扔了,我超级新的JavaScript /服务器开发 – MadeByDouglas