【发布时间】:2019-02-28 12:08:17
【问题描述】:
我对 DialogFlow 完全陌生.. 我想创建一个聊天机器人,我可以向它提问,它会以从我的 Firebase Firestore 数据库中检索到的值进行响应。
我已经创建了必要的意图 (GetPopulationInCity) 并选择了Enable webhook call for this intent
我最好将 DialogFlow Fulfillment 与我的其他 CloudFunction 应用一起使用。
我使用了以下示例中的代码:
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
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(`Welcome to my agent!`);
}
function GetPopulationInCity(agent) {
//Search Firestore for value, if found =>
agent.add(`There are 10,000 people living in XXX`); //should it be ask or something like send or return?
}
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('Get Population', GetPopulationInCity);
intentMap.set('Default Fallback Intent', fallback);
agent.handleRequest(intentMap);
});
但我不知道如何为我的意图创建一个处理程序并返回一个值。有没有人可以帮帮我?
【问题讨论】:
标签: node.js firebase google-cloud-functions dialogflow-es