title: dialogflow chatbot how to go to firestore database and return with support relevant questions?
body: <p>I am using "firestore" database for my "dialogflow" chat bot which I already created for an online grocery store. The problem is: I want my chatbot to initially ask questions from users to find the proper item title in my database and then return to user by asking 3-4 support relevant questions about that item. the questions must be the item attributes (Brand, color, size...) and will vary from one item to another. so the chatbot will stream down the user to find the best item.
  can you please help me to find the answer? I already created the codes but they don't work and I do not know what is wrong with that. If you already created this and have the index.js file, I appreciate to propose me here. </p>
  
  <pre><code> index.js:
  
      'use strict';
  
  const functions = require('firebase-functions');
  // Import admin SDK
  const admin = require('firebase-admin');
  const {
    WebhookClient
  } = require('dialogflow-fulfillment');
  process.env.DEBUG = 'dialogflow:*'; // enables lib debugging statements
  admin.initializeApp(functions.config().firebase);
  // here we get the database in a variable
  const db = admin.firestore();
  const data = {...};
  // Add a new document in collection "dialogflow" with document ID 'agent'
    const dialogflowAgentRef = db.collection('dialogflow').doc('agent').set(data); 
  exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) =&gt; {
    const agent = new WebhookClient({
      request,
      response
    });
   function writeToDb(agent) {
      // Get parameter from Dialogflow with the string to add to the database doc
      const databaseEntry = agent.parameters.databaseEntry;
    // Get the database collection 'dialogflow' and document 'agent' and store
      // the document  {entry: "&lt;value of database entry&gt;"} in the 'agent' document
        const dialogflowAgentRef = db.collection('dialogflow').doc('agent').where('title', '==', title);
  
      return db.runTransaction(t =&gt; {
        t.set(dialogflowAgentRef, {
          entry: databaseEntry
        });
        return Promise.resolve('Write complete');
      }).then(doc =&gt; {
        agent.add(`Wrote "${databaseEntry}" to the Firestore database.`);
      }).catch(err =&gt; {
        console.log(`Error writing to Firestore: ${err}`);
        agent.add(`Failed to write "${databaseEntry}" to the Firestore database.`);
      });
    }
  function readFromDb(agent) {
      // Get the database collection 'dialogflow' and document 'agent'
      const dialogflowAgentDoc = db.collection('dialogflow/agent/rss/channel/item'); // .doc('agent')
  
      // Get the value of 'entry' in the document and send it to the user
      return dialogflowAgentDoc.get()
        .then(doc =&gt; {
          if (!doc.exists) {
            agent.add('No data found in the database!');
          } else {
            agent.add(doc.data().entry);
          }
          return Promise.resolve('Read complete');
        }).catch(() =&gt; {
          agent.add('Error reading entry from the Firestore database.');
          agent.add('Please add a entry to the database first by saying, "Write &lt;your phrase&gt; to the database"');
        });
    }
    // Map from Dialogflow intent names to functions to be run when the intent is matched
    let intentMap = new Map();
    intentMap.set('ReadFromFirestore', readFromDb);
    intentMap.set('WriteToFirestore', writeToDb);
    agent.handleRequest(intentMap);
  });
  </code></pre>