I am currently doing a project using DialogFlow
and Firebase
Database. My main concern, and I have been trying to figure it out for a long time is, how do I take a user input and search through the Firebase
database for it?
As you can see in the code, I have the if else statement to help me filter it out for now, however as more events are being stored the database,I figured out that the if else statement will not be efficient and viable. So, do advise me on how to best take in a user's input and search the database per their request. For example, they might ask "What events are there on 15th August?", the function should then search the database for 15th August, and inform them of any events on that day. Hope to hear from you soon!
function askDate(agent) {
const date1 = agent.parameters.date;
return admin.database().ref('date').transaction((date)=>
{
let askdate = date.askDate;
let activity = date.activity;
let askdate1 = date.twelfthAugust.askDate;
let activity1 = date.twelfthAugust.activity;
let askdate2 = date.fourthAugust.askDate;
let activity2 = date.fourthAugust.activity;
let askdate3 = date.ninthAugust.askDate;
let activity3 = date.ninthAugust.activity;
if (date1 == askdate)
{
agent.add("We have " + activity);
}
else if (date1 == askdate1)
{
agent.add("We have " + activity1);
}
else if (date1 == askdate2)
{
agent.add("We have " + activity2);
}
else if (date1 == askdate3)
{
agent.add("We have " + activity3);
}
else
{
agent.add("We do not have any events on this day!");
}
return date;
},
function (error, isSuccess) {
console.log('Success: ' + isSuccess);
});
}