Я совершенно новичок в 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);
});
но я понятия не имею, как создать обработчик для моего намерения и вернуть значение.Есть ли кто-нибудь, кто мог бы помочь мне?