-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
144 lines (132 loc) · 4.31 KB
/
index.js
File metadata and controls
144 lines (132 loc) · 4.31 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
'use strict';
// Import the Dialogflow module and response creation depEndencies
// from the Actions on Google client library.
const {
dialogflow,
BasicCard,
Permission,
Suggestions,
Carousel,
Image,
Table,
List,
} = require('actions-on-google');
var events = require('./events').events;
var ComingEvents = require('./events').ComingEvents;
var team = require('./team').team;
// Import the firebase-functions package for deployment.
const functions = require('firebase-functions');
// Instantiate the Dialogflow client.
const app = dialogflow({debug: true});
const rp = require('request-promise');
// Handle the Dialogflow intent named 'Default Welcome Intent'.
app.intent('Default Welcome Intent', (conv) => {
const name = conv.user.storage.userName;
if (!name) {
// Asks the user's permission to know their name, for personalization.
conv.ask(new Permission({
context: 'Hi there, to get to know you better',
permissions: 'NAME',
}));
} else {
conv.ask(`Hi again, ${name}. How can I help you?`);
conv.ask(new Suggestions('Past events', 'Coming events', 'Team'));
}
});
// Handle the Dialogflow intent named 'actions_intent_PERMISSION'. If user
// agreed to PERMISSION prompt, then boolean value 'permissionGranted' is true.
app.intent('actions_intent_PERMISSION', (conv, params, permissionGranted) => {
if (!permissionGranted) {
// If the user denied our request, go ahead with the conversation.
conv.ask(`OK, no worries. How can I help you?`);
conv.ask(new Suggestions('Past events', 'Coming events', 'Team'));
} else {
// If the user accepted our request, store their name in
// the 'conv.user.storage' object for future conversations.
conv.user.storage.userName = conv.user.name.display;
conv.ask(`Thanks, ${conv.user.storage.userName}. ` +
`What do you want to know?`);
conv.ask(new Suggestions('Past events', 'future events', 'team'));
}
});
app.intent('past_events', (conv) => {
conv.ask(new Suggestions('team', 'Bye', 'coming events'));
let Title, StartDate,EndDate;
let rows = [];
const y = events.length;
for(var i=0;i<y;i++)
{
Title = events[i].title;
StartDate = events[i].startDate;
EndDate = events[i].endDate;
rows.push([Title, StartDate, EndDate]);
}
conv.ask('Here is the list of all events. ');
conv.ask(new Table({
dividers: true,
columns: ['Title','StartDate','EndDate'],
rows: rows,
}));
conv.ask('Would you like to know anything else?')
});
app.intent('comingEvents', (conv) =>{
conv.ask(new Suggestions('team', 'past events'));
let Title, StartDate, EndDate;
let rows =[];
const z = ComingEvents.length;
if(z === 0)
{
conv.ask('No coming events. ');
conv.ask('Would you like to know anything else?')
}
else {
for(var i=0;i<z;i++)
{
Title = ComingEvents[i].title;
StartDate = ComingEvents[i].startDate;
EndDate = ComingEvents[i].endDate;
rows.push([Title, StartDate, EndDate]);
}
conv.ask('Here is the list of all events. ');
conv.ask(new Table({
dividers: true,
columns: ['Title','StartDate','EndDate'],
rows: rows,
}));
conv.ask('Would you like to know anything else?')
}
});
app.intent('team', (conv) => {
conv.ask(new Suggestions('Bye'))
let Name, Role;
let rows = [];
const x = team.length;
for(var i=0;i<x;i++)
{
Name = team[i].name;
Role = team[i].role;
rows.push([Name, Role]);
}
conv.ask(`Here are all team members. `);
conv.ask(new Table({
dividers: true,
columns: ['Name','Role'],
rows: rows,
}));
});
// Handle the Dialogflow NO_INPUT intent.
// Triggered when the user doesn't provide input to the Action
app.intent('actions_intent_NO_INPUT', (conv) => {
// Use the number of reprompts to vary response
const repromptCount = parseInt(conv.arguments.get('REPROMPT_COUNT'));
if (repromptCount === 0) {
conv.ask('Which event would you like to hear about?');
} else if (repromptCount === 1) {
conv.ask(`Please say the name of event`);
} else if (conv.arguments.get('IS_FINAL_REPROMPT')) {
conv.close(`Sorry we're having trouble. Let's ` +
`try this again later. Goodbye.`);
}
});
// Set the DialogflowApp object to handle the HTTPS POST request.
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);