-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsever.js
66 lines (48 loc) · 1.92 KB
/
sever.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';
const functions = require('firebase-functions');
const firebase = require('firebase');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
var firebaseConfig = {
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
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 fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function getData(agent) {
agent.add(`data: from vrijraj`);
}
function showNumber(agent){
console.log(`agent: ${agent}`);
//let conv = agent.conv(); // Get Actions on Google library conv instance
// conv.ask(
var a = agent.parameters.number;
var b;
firebase.database().ref('number').push({number:a});
//agent.add(`Your Number is : ${a}`);
firebase.database().ref('data').on('value',snap=>{
b = snap.val();
agent.add(`Your Data is ${b} and number is: ${a}`);
console.log(`hellow froom ${b}`);
});
}
// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
intentMap.set('GetData', getData);
intentMap.set('showNumber', showNumber);
agent.handleRequest(intentMap);
});