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
JavaScript
x
39
39
1
'use strict';
2
3
const functions = require('firebase-functions');
4
const {WebhookClient} = require('dialogflow-fulfillment');
5
const requestLib = require('request');
6
7
8
9
const admin = require('firebase-admin');
10
admin.initializeApp();
11
const db = admin.firestore();
12
13
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
14
15
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
16
const agent = new WebhookClient({ request, response });
17
const timestamp =new Date().toLocaleString();
18
let MyData = {};
19
20
21
function getTeamHandler(agent) {
22
MyData.team = agent.parameters.team ;
23
MyData.user_id = agent.originalRequest.payload.data.sender.id;
24
}
25
26
function getPwiHandler(agent) {
27
MyData.pwi = agent.parameters.with_pwi ;
28
return admin.database().ref('/spo').push({temp: MyData.team,user_id :MyData.user_id,with_pwi : MyData.pwi,timestamp:timestamp}).then((snapshot) => {
29
agent.add(`Please wait for the response for code : ${MyData.team}`);
30
});
31
}
32
33
34
let intentMap = new Map();
35
intentMap.set('1.team', getTeamHandler);
36
intentMap.set('2.pwi', getPwiHandler);
37
agent.handleRequest(intentMap);
38
});
39
Advertisement
Answer
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