-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (33 loc) · 1.36 KB
/
index.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
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
//Database Connection
const admin = require('firebase-admin');
admin.initializeApp({
credential: admin.credential.applicationDefault(),
databaseURL: 'ws://FIREBASEURL'
});
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 handle(PARAMETER)(agent){
const sent(PARAMETER) = agent.parameters.(PARAMETER);
agent.add('Thank You...');
return admin.database().ref('NAME').transaction(((PARAMETER)) => {
if((PARAMETER) !== null) {
let new(PARAMETER) = sent(PARAMETER);
(PARAMETER) = new(PARAMETER);
agent.add(`Sent ` + new(PARAMETER));
}
return (PARAMETER);
}, function(error, isSuccess) {
console.log('Added (PARAMETER) to Database: ' + isSuccess);
});
}
let intentMap = new Map();
intentMap.set('NAMEOFINTENT', handle(PARAMETER));
agent.handleRequest(intentMap);
});