title: Webhook call failed. Error: 500 Internal Server Error | Dialogflow | Firebase
body: <p>I am trying to create a firebase function to send the API response to dialogflow, using fulfillment webhook, but I am facing Error: 500.</p>
  
  <pre><code>const functions = require('firebase-functions');
  var request = require('request')
  
  exports.webhook = functions.https.onRequest((request, response) =&gt; {
  
          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);
          });
      });
  </code></pre>
  
  <p>The warning I got while deploying is</p>
  
  <pre><code>  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.
  </code></pre>
  
  <p>for example if <code>params.find</code> is <code>evoke</code> then parsing the API response should give this result </p>
  
  <p><a href="https://islam360api.herokuapp.com/evoke" rel="nofollow noreferrer">https://islam360api.herokuapp.com/evoke</a></p>
  
  <pre><code>{"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. "}
  </code></pre>
  
  <p><strong>Edit:</strong>
  This is the response I get while deploying firebase function</p>
  
  <pre><code>C:\Users\mnauf\Desktop\IOT\islam360\firebase&gt;firebase deploy --only functions
  
  === Deploying to 'islam360-3cf18'...
  
  i  deploying functions
  Running command: npm --prefix "$RESOURCE_DIR" run lint
  
  &gt; functions@ lint C:\Users\mnauf\Desktop\IOT\islam360\firebase\functions
  &gt; 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
  </code></pre>
  
  <p><strong>Logs</strong></p>
  
  <p><strong>RAW API RESPONSE</strong></p>
  
  <pre><code>{
    "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"
  }
  </code></pre>
  
  <p><strong>FULFILLMENT REQUEST</strong></p>
  
  <pre><code>{
    "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"
  }
  </code></pre>
  
  <p><strong>FULFILLMENT RESPONSE</strong></p>
  
  <pre><code>Error: could not handle the request
  </code></pre>
  
  <p><strong>FULFILLMENT STATUS</strong></p>
  
  <pre><code>Webhook call failed. Error: 500 Internal Server Error
  </code></pre>
  
  <p><strong>Console Screenshot</strong></p>
  
  <p><a href="https://i.stack.imgur.com/8Y3w2.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Y3w2.jpg" alt="enter image description here"></a></p>
  
  <p><strong>Firebase Logs</strong></p>
  
  <p><a href="https://i.stack.imgur.com/wn1qv.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wn1qv.jpg" alt="enter image description here"></a></p>
  
  <p>From firebase logs, it seems like, I have to pay. Do I have to?</p>