0

I am creating an agent which can read a list of data from a database (Real Time Database on Firebase). With context and parameters, I can trigger the webhook and get the data I want.

But because the result is a List, output text will be too long to speak all data out in one time, so I want to return one child from the list each time and ask the user "Do you want to read the next section?". If the user says "Yes", I will continue reading likewise until the end. And if the user says "No", I will trigger an event.

For looping I am using this:

ref.once('value', function(snapshot) {
   snapshot.forEach(function(childSnapshot) {
   var childKey = childSnapshot.key;
   var childData = childSnapshot.val();
   // ...
  });
});

(https://firebase.google.com/docs/database/web/lists-of-data#listen_for_value_events)

But this gives all data from the list at one. How do I output one data and ask the user for permission, and then continue with next data in the list? My query is how do I ask for the permission through Dialogflow-fulfillment in between of reading the list and then continue with the list according to the response given by the user? Please write for any clarifications.

Shivam
  • 192
  • 1
  • 12
  • You can display the first item retrieved then add conv.ask to know whether he wants to continue to see the complete list and add a follow-up intent displaying a list of items retrieved before. – Sairaj Sawant Dec 05 '18 at 14:30
  • conv.ask doesn't work – Shivam Dec 06 '18 at 11:38
  • What do you mean "conv.ask doesn't work"? – Prisoner Dec 06 '18 at 11:57
  • @Prisoner, Whenever, even wherever, I put `conv.ask` under function exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { }, dialogflow doesn't comply with fulfillment. Here is the link to `index.js` : https://gist.github.com/shivam-k/49cfd05b36eb52d219f99b20cf285f03 – Shivam Dec 06 '18 at 14:48
  • This sounds like a different question, which I suggest you ask as a new SO question, including what happens when you try and screen shots of your Intents. More about this question in the answers below. – Prisoner Dec 06 '18 at 16:40

1 Answers1

1

you have to use a combination of orderByValue()/orderByChild(), limitToFirst() and startAt() methods to limit the number of records returned to you.

orderByValue()/orderByChild() will require a property/child that defines the order you want the items to show up.

limitToFirst() will decide how many rows you expect to get in each call

startAt() will need the value of the field you are sorting and have to be updated each time you request the next group of rows.

you can read more about these methods here

Reza Nasiri
  • 1,360
  • 1
  • 6
  • 19
  • Doesn't it concern Admin SDK? Actually, I am trying to do it with Dialogflow's fulfillment. Would you let me know how it is possible? – Shivam Dec 06 '18 at 14:55
  • Yes, this is using the Firebase Admin SDK, which you would do in your fulfillment webhook. – Prisoner Dec 06 '18 at 16:38