node.js - 获取用户输入并通过 Firebase 数据库进行搜索
问题描述
我目前正在使用DialogFlow
和Firebase
数据库做一个项目。我主要关心的是,我一直试图弄清楚很长时间是,我如何接受用户输入并在Firebase
数据库中搜索它?正如您在代码中看到的那样,我现在有 if else 语句来帮助我将其过滤掉,但是随着越来越多的事件被存储在数据库中,我发现 if else 语句将不会有效和可行。所以,请告诉我如何最好地接受用户的输入并根据他们的请求搜索数据库。例如,他们可能会问“8 月 15 日有什么活动?”,然后该功能应在数据库中搜索 8 月 15 日,并告知他们当天的任何活动。希望早日收到你的消息!
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);
});
}
解决方案
您只需要设计意图来捕获用户的日期。将此日期传递给 webhook 并使用类似 " select event from DB where date = userProvidedDate
"
而不是 if else,您应该根据日期从数据库中获取事件。你需要寻找你将如何做到这一点。
推荐阅读
- ruby-on-rails - Rails 方法而不是模型的 has_many 中的 id
- regex - 正则表达式等于或高于 125233000
- javascript - 更新 observable 中的值而不解析先前的运算符
- java - 当我在我的 android mobile samsung j7 prime 上运行 android 项目时,手机无法授予权限
- ionic-framework - 通过 Ionic 向 Web API 发送多条记录
- javascript - 无法使用 Laravel Mix 访问 Vue 组件中的 js-cookie
- android - 为什么 Proguard 不会混淆某些包私有类?
- apache - 在 Apache 2.4 上使用带有反向代理的输出过滤器
- java - 如何在java项目中设置maven本地repo
- python - 如何在 Python 2.7 上使用没有控制台的子进程不断监听外部程序的输出