【问题标题】:Webhook call failed. Error: 500 Internal Server Error | Dialogflow | FirebaseWebhook 调用失败。错误:500 内部服务器错误 |对话流 |火力基地
【发布时间】:2019-03-21 03:33:12
【问题描述】:

我正在尝试使用实现 webhook 创建一个 firebase 函数来将 API 响应发送到 dialogflow,但我遇到了错误:500。

const functions = require('firebase-functions');
var request = require('request')

exports.webhook = functions.https.onRequest((request, response) => {

        console.log("request.body.result.parameters: ", request.body.result.parameters);
        let params = request.body.result.parameters;

        var options = {
            url: `https://islam360api.herokuapp.com/${params.find}`,
            json:true
        }
        request(options, function(error, response, body){
            if(error) response.send(error);
            else response.send(body);
        });
    });

我在部署时收到的警告是

  13:26  warning  Unexpected function expression  prefer-arrow-callback

✖ 1 problem (0 errors, 1 warning)
  0 errors and 1 warning potentially fixable with the `--fix` option.

例如,如果params.findevoke,那么解析 API 响应应该给出这个结果

https://islam360api.herokuapp.com/evoke

{"speech":"In Surat-ul-Fateha, Ayat Number: 7, Quran says:  not of those who have evoked [Your] anger or of those who are astray. ","displayText":"In Surat-ul-Fateha, Ayat Number: 7, Quran says:  not of those who have evoked [Your] anger or of those who are astray. "}

编辑: 这是我在部署 firebase 功能时得到的响应

C:\Users\mnauf\Desktop\IOT\islam360\firebase>firebase deploy --only functions

=== Deploying to 'islam360-3cf18'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint C:\Users\mnauf\Desktop\IOT\islam360\firebase\functions
> eslint .


C:\Users\mnauf\Desktop\IOT\islam360\firebase\functions\index.js
  13:26  warning  Unexpected function expression  prefer-arrow-callback

✖ 1 problem (0 errors, 1 warning)
  0 errors and 1 warning potentially fixable with the `--fix` option.

+  functions: Finished running predeploy script.
i  functions: ensuring necessary APIs are enabled...
+  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (37.98 KB) for uploading
+  functions: functions folder uploaded successfully
i  functions: updating Node.js 6 function webhook(us-central1)...
+  functions[webhook(us-central1)]: Successful update operation.

+  Deploy complete!

Please note that it can take up to 30 seconds for your updated functions to propagate.
Project Console: https://console.firebase.google.com/project/islam360-3cf18/overview

日志

原始 API 响应

{
  "id": "ed1108a6-a938-4cfb-8fe1-7a1fa0c856e4",
  "timestamp": "2019-03-20T18:02:22.676Z",
  "lang": "en",
  "result": {
    "source": "agent",
    "resolvedQuery": "where does Quran talk about evoke",
    "action": "",
    "actionIncomplete": false,
    "parameters": {
      "find": "evoke"
    },
    "contexts": [],
    "metadata": {
      "isFallbackIntent": "false",
      "webhookResponseTime": 129,
      "intentName": "find",
      "intentId": "dd549c44-25bd-48fa-915f-4810759968eb",
      "webhookUsed": "true",
      "webhookForSlotFillingUsed": "false"
    },
    "fulfillment": {
      "speech": "Something went wrong",
      "messages": [
        {
          "type": 0,
          "speech": "Something went wrong"
        }
      ]
    },
    "score": 1
  },
  "status": {
    "code": 206,
    "errorType": "partial_content",
    "errorDetails": "Webhook call failed. Error: 500 Internal Server Error"
  },
  "sessionId": "4d887eaa-2dc1-649d-9ae6-238a6d79f085"
}

履行请求

{
  "id": "ed1108a6-a938-4cfb-8fe1-7a1fa0c856e4",
  "timestamp": "2019-03-20T18:02:22.676Z",
  "lang": "en",
  "result": {
    "source": "agent",
    "resolvedQuery": "where does Quran talk about evoke",
    "action": "",
    "actionIncomplete": false,
    "parameters": {
      "find": "evoke"
    },
    "contexts": [],
    "metadata": {
      "isFallbackIntent": "false",
      "webhookResponseTime": 129,
      "intentName": "find",
      "intentId": "dd549c44-25bd-48fa-915f-4810759968eb",
      "webhookUsed": "true",
      "webhookForSlotFillingUsed": "false"
    },
    "fulfillment": {
      "speech": "Something went wrong",
      "messages": [
        {
          "type": 0,
          "speech": "Something went wrong"
        }
      ]
    },
    "score": 1
  },
  "status": {
    "code": 206,
    "errorType": "partial_content",
    "errorDetails": "Webhook call failed. Error: 500 Internal Server Error"
  },
  "sessionId": "4d887eaa-2dc1-649d-9ae6-238a6d79f085"
}

履行响应

Error: could not handle the request

履行状态

Webhook call failed. Error: 500 Internal Server Error

控制台截图

Firebase 日志

从 firebase 日志看来,我必须付费。我必须这样做吗?

【问题讨论】:

  • Firebase 日志仍然丢失,转到 firebase 控制台并选择函数,然后选择日志并共享这些日志,我还建议您将整个代码包装在 try catch 块中以捕获每个错误并记录它

标签: node.js firebase dialogflow-es


【解决方案1】:

如果您使用 dialogflow v2:

 request(options, function(error, response, body){
     if(error) 
         response.send({ fulfillmentText: "error in api call"});
     else 
         response.send({ fulfillmentText: body.speech });
 });

如果您使用的是 dilogflow v1(即将弃用)

 request(options, function(error, response, body){
     if(error) 
         response.send({ speech: "error in api call"});
     else 
         response.send({ speech: body.speech });
 });

要检查/更改 dialogflow 的版本,请转到 dilogflow 控制台(https://console.dialogflow.com), 按齿轮图标,并在一般部分查看,不要忘记按保存按钮以防您更改它

更新

根据您的 Firebase 功能日志,是的,您需要付费,

请注意,firebase 函数只允许调用 o ly google api,并且不允许第三方 api 在免费配额中,您需要将您的计划移动到“按需付费”,因为它是最便宜的

或者,你可以使用 express server 来制作 webhook,你可以将它部署在 heroku 云上,他们允许在他们的免费计划中调用第三方 api

【讨论】:

  • 使用版本 1
猜你喜欢
  • 1970-01-01
  • 2018-01-02
  • 2023-02-17
  • 1970-01-01
  • 1970-01-01
  • 2012-10-11
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
相关资源
最近更新 更多