2017-03-16 72 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