使用http.get时必须设置final_response

时间:2018-05-03 13:54:38

标签: node.js webhooks dialogflow fulfillment

我尝试使用dialogflow和webhook。 Everythink一直有效,直到我添加一个http请求。我有以下错误:

  

必须设置MalformedResponse'inal_response'。

这是我的代码:

function askMovie (response) {
  return new Promise((resolve, reject) => {
    // resolve("THIS ONE WORKS if I comment the http.get");

    http.get('http://www.omdbapi.com/?apikey=[MY_HIDDEN_API_KEY]&s=lego', res => {
       let raw = '';
       res.on('data', chunk => raw += chunk);
       res.on('end', () => {
          resolve("OK");
        });
       res.on('error', (error) => {
          reject(error);
       });

    });
  });
}

exports.dialogflowWebhook = functions.https.onRequest((request, response) => {
  askMovie(response).then((output) =>{
    response.json({ fulfillmentText: 'Request Success' });
  }).catch((error) => {
    response.json({ fulfillmentText: 'No movies' });
  })
});

我尝试了其他样品,但总是出现同样的错误。

失败时的回复:

{
  "responseMetadata": {
    "status": {
      "code": 10,
      "message": "Failed to parse Dialogflow response into AppResponse because of empty speech response",
      "details": [
        {
          "@type": "type.googleapis.com/google.protobuf.Value",
          "value": "{\"id\":\"fdcfc60e-8da3-42cc-84a8-a5de5f4accf8\",\"timestamp\":\"2018-05-03T13:46:26.646Z\",\"lang\":\"fr-fr\",\"result\":{},\"status\":{\"code\":206,\"errorType\":\"partial_content\",\"errorDetails\":\"Webhook call failed. Error: 500 Internal Server Error\"},\"sessionId\":\"1525354490725\"}"
        }
      ]
    }
  }
}

我为我的webhook使用firebase函数。

1 个答案:

答案 0 :(得分:0)

你想念你的" fulfillment.speech" Json元素。在服务器日志上验证这一点。需要默认语音响应。

"fulfillment": {
  "speech": "Nice to meet you, Sam!"
},

https://developers.google.com/actions/reference/v1/dialogflow-webhook