根据数据库检查日期事件

时间:2018-07-30 03:43:29

标签: javascript firebase-realtime-database dialogflow

我正在为此项目使用Dialogflow和Firebase数据库。我正在尝试接受用户在特定日期输入的事件,例如“ 8月5日发生什么事件?”。但是,我一直不确定。 Asking the question on DialogIntent for asking of the eventFirebase 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`
    });
}

});

0 个答案:

没有答案