簡體   English   中英

Webhook呼叫失敗。 錯誤:500內部服務器錯誤| Dialogflow | 火力地堡

[英]Webhook call failed. Error: 500 Internal Server Error | Dialogflow | Firebase

我正在嘗試創建一個firebase函數,使用履行webhook將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日志看來,我必須付錢。 我一定要嗎?

如果您使用的是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 });
 });

檢查/更改對話框流量版本,轉到dilogflow控制台( https://console.dialogflow.com ),按齒輪圖標,然后在常規部分查看,不要忘記按保存按鈕以防萬一

更新

根據你的firebase功能日志,你需要支付,

請注意,firebase功能只允許調用谷歌api,並且不允許第三方api免費配額,你需要將你的計划轉移到“按需付費”,因為它是最便宜的

或者,你可以使用快速服務器制作webhook,你可以將它部署在heroku雲上,它們允許在他們的免費計划中使用第三方api呼叫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM