0

I'm creating a dialogflow bot, for the fulfillment of the bot I am using a node server (on google cloud functions) to retrieve data through a function returning a promise

I've tried adding a agent.setFollowupEvent('ExtendTimeOut'); because I read here that this would extend the timeout (of 5 secs) but I don't really know where to put it and it doesn't seem to work.

I'm currently using the db.collection("details").where("keywords", "array-contains", keyword) to retrieve data from Firestore

DB Structure:

users
  |__> userID
         |__> user properties
         |__> [Array of keywords (ex. fifa, gta, etc)]

Dialogflow fulfillment function:

function GetUserDetails(agent) {
        var keyword = agent.parameters.any //keyword to search for

        return new Promise( function( resolve, reject ){
            db.collection("details").where("keywords", "array-contains", keyword)
            .get()
            .then(function(querySnapshot) {

                querySnapshot.forEach(function(doc) {
                    console.log("Contact data:", doc.data());
                    agent.add("these are the user details for " + doc.data()["name"]));
                    agent.add(doc.data()["username"]);
                    agent.add(doc.data()["useremail"]);

                });
                resolve()
            })
            .catch(function(error) {
                reject( error );
                console.log("Error getting documents: ", error);
            });

        });
}

let intentMap = new Map();
intentMap.set('GetUserDetails', GetUserDetails);;
agent.handleRequest(intentMap);

Does anyone know how to speed up the data retrieval or extend this timeout?

1 Answers1

0

Two things immediately come to mind to make sure you're improving performance:

  • Make sure the keywords field is indexed. The array-contains operation is expensive, and this can help.
  • Consider limiting how many are returned. If there are a lot that get returned, this decreases performance dramatically (and makes for a very cluttered response).
Prisoner
  • 49,922
  • 7
  • 53
  • 105