首页 > 解决方案 > 使用 http.get 时必须设置 final_response

问题描述

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

必须设置 MalformedResponse 'final_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 函数。

标签: node.jswebhooksdialogflow-esfulfillment

解决方案


您缺少“fulfillment.speech” Json 元素。在您的服务器日志上验证这一点。需要默认语音响应。

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

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


推荐阅读