我正在为此项目使用Dialogflow和Firebase数据库。我正在尝试接受用户在特定日期输入的事件,例如“ 8月5日发生什么事件?”。但是,我一直不确定。 Asking the question on Dialog,Intent for asking of the event,Firebase Database for events dates reference
const db = admin.database();
const action = request.body.queryResult.action;
if (action === 'event_date') {
const courses = request.body.queryResult.parameters.date.trim();
const ref = db.ref(`events`);
ref.once('value').then((snapshot) => {
const result = snapshot.val();
if (result === null) {
response.json({
fulfillmentText: `We do not have any events on this day. Please try another date!`
});
return;
}
response.json({
fulfillmentText: `We have ${result.name}`,
source: action
});
}).catch((err) => {
response.json({
fulfillmentText: `I don't know what is it`
});
})
} else {
response.json({
fulfillmentText: `I don't know what is it`
});
}
});