title: Dialogflow Webhook Firestore returns webhook failed status code 04, How to fix and get output from the firestore?
body: <p>I am trying to integrate dialogflow with firestore but I can't get the required output. Diagnostic Info provides the below error. I need to get the response from the firestore according to the given input from the agent that's the basic requirement but I get this error while integrating.</p>
  <pre><code> {
    &quot;responseId&quot;: &quot;a6a119a8-c406-4af2-aab0-b6863fb091a4-59c3eb0f&quot;,
    &quot;queryResult&quot;: {
      &quot;queryText&quot;: &quot;15APC2375&quot;,
      &quot;parameters&quot;: {
        &quot;regno&quot;: &quot;15APC2375&quot;
      },
      &quot;allRequiredParamsPresent&quot;: true,
      &quot;intent&quot;: {
        &quot;name&quot;: &quot;projects/cis-bot-yhrvph/agent/intents/e3b1292b-89b1-48b7-b4b4-805a63d08168&quot;,
        &quot;displayName&quot;: &quot;request-results&quot;
      },
      &quot;intentDetectionConfidence&quot;: 0.3,
      &quot;diagnosticInfo&quot;: {
        &quot;webhook_latency_ms&quot;: 4892
      },
      &quot;languageCode&quot;: &quot;en&quot;
    },
    &quot;webhookStatus&quot;: {
      &quot;code&quot;: 4,
      &quot;message&quot;: &quot;Webhook call failed. Error: DEADLINE_EXCEEDED.&quot;
    }
  }
  </code></pre>
  <p>My Package.json includes the below code.</p>
  <pre><code>{
    &quot;name&quot;: &quot;dialogflowFirebaseFulfillment&quot;,
    &quot;description&quot;: &quot;This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase&quot;,
    &quot;version&quot;: &quot;0.0.1&quot;,
    &quot;private&quot;: true,
    &quot;license&quot;: &quot;Apache Version 2.0&quot;,
    &quot;author&quot;: &quot;Google Inc.&quot;,
    &quot;engines&quot;: {
      &quot;node&quot;: &quot;10&quot;
    },
    &quot;scripts&quot;: {
      &quot;start&quot;: &quot;firebase serve --only functions:dialogflowFirebaseFulfillment&quot;,
      &quot;deploy&quot;: &quot;firebase deploy --only functions:dialogflowFirebaseFulfillment&quot;
    },
    &quot;dependencies&quot;: {
      &quot;firebase&quot;: &quot;^7.13.2&quot;,
      &quot;actions-on-google&quot;: &quot;^2.2.0&quot;,
      &quot;firebase-admin&quot;: &quot;^5.13.1&quot;,
      &quot;firebase-functions&quot;: &quot;^2.0.2&quot;,
      &quot;dialogflow&quot;: &quot;^0.6.0&quot;,
      &quot;dialogflow-fulfillment&quot;: &quot;^0.5.0&quot;
    }
  }
  </code></pre>
  <p>As well as index.js includes the below code.</p>
  <pre><code>'use strict';
   
  const firebase = require('firebase');
  
  const functions = require('firebase-functions');
  const admin = require('firebase-admin');
  const {WebhookClient} = require('dialogflow-fulfillment');
  const {Card, Suggestion} = require('dialogflow-fulfillment');
  
  admin.initializeApp();
  const db = admin.firestore();
  
  
  process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
   
  exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) =&gt; {
    const agent = new WebhookClient({ request, response });
    console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
    console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
   
    function welcome(agent) {
      agent.add(`Welcome to CIS BOT!`);
    }
   
    function fallback(agent) {
      agent.add(`Please Contact the Front Desk for more information`);
    }
    
    function getResults(agent){
      const regno=agent.parameters.regno;
      const dialogflowAgentDoc = db.collection('results').where(&quot;reg_id&quot;,&quot;==&quot;,'15APC2375')
      .get()
      .then((querySnapshot) =&gt; {
          querySnapshot.forEach((doc) =&gt; {
              // doc.data() is never undefined for query doc snapshots
              agent.add(doc.data().grade);
          });
        }).catch(() =&gt; {
          agent.add('Error reading entry from the Firestore database.');
          agent.add('Please add a entry to the database first by saying, &quot;Write &lt;your phrase&gt; to the database&quot;');
        });
    }
    
  let intentMap = new Map();
    intentMap.set('Default Welcome Intent', welcome);
    intentMap.set('Default Fallback Intent', fallback);
    intentMap.set('request-results', getResults);
    // intentMap.set('your intent name here', googleAssistantHandler);
    agent.handleRequest(intentMap);
  });
  </code></pre>