【发布时间】:2019-01-12 12:17:09
【问题描述】:
我有一个 Cloud Firestore 数据库,其中存储了 2017 年英格兰所有城市的居民数量。
然后我有一个 Dialogflow。每当我将一个城市的名称告诉 Dialogflow 时,我希望它从 Firestore 中获取该城市的居民数量并将其返回给 Dialogflow。
具体来说,我想通过内联编辑器来实现它。
问题:为了实现这一点,我需要在下面的代码中添加哪些代码行?
这是我在 Dialogflow > Fulfillment > index.js 的内联编辑器中编写的代码:
'use strict';
const functions = require('firebase-functions');
const firebaseAdmin = require('firebase-admin');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const App = require('actions-on-google').DialogflowApp;
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
function welcome(agent) {
agent.add(`Hello and welcome!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});
【问题讨论】:
标签: node.js firebase firebase-authentication google-cloud-firestore dialogflow-es