I have an issue saving multiple parameters from different intents in dialogflow firebase fullfillment. I've tried declaring a global variable to store the data there but to no avail . here is what I have so far.
I would like to save the parameters from multiple intents to a firebase db
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const requestLib = require('request');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const agent = new WebhookClient({ request, response });
const timestamp =new Date().toLocaleString();
let MyData = {};
function getTeamHandler(agent) {
MyData.team = agent.parameters.team ;
MyData.user_id = agent.originalRequest.payload.data.sender.id;
}
function getPwiHandler(agent) {
MyData.pwi = agent.parameters.with_pwi ;
return admin.database().ref('/spo').push({temp: MyData.team,user_id :MyData.user_id,with_pwi : MyData.pwi,timestamp:timestamp}).then((snapshot) => {
agent.add(`Please wait for the response for code : ${MyData.team}`);
});
}
let intentMap = new Map();
intentMap.set('1.team', getTeamHandler);
intentMap.set('2.pwi', getPwiHandler);
agent.handleRequest(intentMap);
});
You can use context to save/use data across multiple intents. You need to set output context and then in next webhook request you can get context what you have set in previous intent