I am using Firebase Cloud Function as fulfilment for my DialogFlow Google Assistant Action, but I need to retrieve data from the Firebase Database before I manage the intent. Here's a code snippet:
var userDataRef = sessionDatabaseRef.child(sessionId);
userDataRef.once("value").then(function(data) {
console.log(data.val());
handleIntentAndProcessResponse();
}).catch(function(){
console.log("No data yet for this session");
handleIntentAndProcessResponse();
});
The function called handleIntentAndProcessResponse
is where the intent logic returns the response by setting the conv.ask(new SimpleResponse(blah))
stuff. When I test this it fails and the Cloud Function log gives me this error:
Error: No response has been set. Is this being used in an async call that was not returned as a promise to the intent handler?
So, how can I handle this async call to the Firebase database so it waits for the response? I need to use the data it returns when I handle the intent.