-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
342 lines (302 loc) · 13.5 KB
/
app.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
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
/*-----------------------------------------------------------------------------
Weekend Fuelbag bot.
created by Yunduz and Evgeny (c) 2018
-----------------------------------------------------------------------------*/
// This loads the environment variables from the .env file
require('dotenv-extended').load();
var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_azure = require("botbuilder-azure");
// Setup Restify Server
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat connector for communicating with the Bot Framework Service
var connector = new builder.ChatConnector({
appId: process.env.MicrosoftAppId,
appPassword: process.env.MicrosoftAppPassword,
openIdMetadata: process.env.BotOpenIdMetadata
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
/*----------------------------------------------------------------------------------------
* Bot Storage: This is a great spot to register the private state storage for your bot.
* We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
* For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure
* ---------------------------------------------------------------------------------------- */
var tableName = 'botdata';
var azureTableClient = new botbuilder_azure.AzureTableClient(tableName, process.env['AzureWebJobsStorage']);
var tableStorage = new botbuilder_azure.AzureBotStorage({ gzipData: false }, azureTableClient);
var bot = new builder.UniversalBot(connector, function (session, args) {
session.send('You totally reached the default message handler. You said \'%s\'.', session.message.text);
});
bot.set('storage', tableStorage);
// Make sure you add code to validate these fields
var luisAppId = process.env.LuisAppId;
var luisAPIKey = process.env.LuisAPIKey;
var luisAPIHostName = process.env.LuisAPIHostName || 'westus.api.cognitive.microsoft.com';
const LuisModelUrl = 'https://' + luisAPIHostName + '/luis/v2.0/apps/' + luisAppId + '?subscription-key=' + luisAPIKey;
// Create a recognizer that gets intents from LUIS, and add it to the bot
var recognizer = new builder.LuisRecognizer(LuisModelUrl);
bot.recognizer(recognizer);
bot.dialog('GreetingDialog',
(session) => {
var message = 'Hello there! I\'m **"Weekend FuelBag"** bot!';
message += '\nI know a lot of information about various resources for low income families and individuals.';
message += '\nFor example, you can ask me about:';
message += '\n- Food';
message += '\n- Mental health';
message += '\n- Housing';
message += '\n- Child care';
message += '\n- Tutoring';
message += '\n- Sports';
message += '\n- Clothing';
message += '\n- Help for your pet';
message += '\n\nOh, and I understand human language just well!';
message += '\nWhat would you like to learn about?';
session.send(message);
session.endDialog();
}
).triggerAction({
matches: 'Greeting'
})
bot.dialog('HelpDialog',
(session) => {
var message = 'Sure, I will help you!';
message += '\nJust as me about some topic like food, mental health or housing in a human language.';
message += '\nI will parse the information from the message and will find an answer from my knowledge base.';
session.send(message);
session.endDialog();
}
).triggerAction({
matches: 'Help'
})
bot.dialog('CancelDialog',
(session) => {
session.send('Sure, let\'s pretend this never happened! What can I help you with?');
session.endDialog();
delete session.conversationData.isFood;
delete session.conversationData.isStudent;
delete session.conversationData.isParent;
delete session.conversationData.isAdult;
}
).triggerAction({
matches: 'Cancel'
})
bot.dialog('GetFoodInfoDialog',
(session) => {
var message = 'Check out the following resources. I hope they help! Let me know if you have more questions!';
if(session.conversationData.isStudent) {
session.send(message);
session.send(getStudentFoodInfo());
} else if (session.conversationData.isAdult) {
session.send(message);
session.send(getAdultFoodInfo());
} else if (session.conversationData.isParent) {
session.send(message);
session.send(getParentFoodInfo());
} else {
session.conversationData.isFood = true;
session.send('Are you a student, parent or adult?');
session.endDialog();
}
session.endDialog();
}
).triggerAction({
matches: 'GetFoodInfo'
})
bot.dialog('IsStudentDialog',
(session) => {
session.conversationData.isStudent = true;
if(session.conversationData.isFood) {
session.send('Check out these resources. Hope this helps! Stay in school :) !');
session.send(getStudentFoodInfo());
delete session.conversationData.isFood;
}
session.endDialog();
}
).triggerAction({
matches: 'IsStudent'
})
bot.dialog('IsParentDialog',
(session) => {
session.conversationData.isParent = true;
if(session.conversationData.isFood) {
session.send('Being a parent is not easy but I hope these resources help!');
session.send(getParentFoodInfo());
delete session.conversationData.isFood;
}
session.endDialog();
}
).triggerAction({
matches: 'IsParent'
})
bot.dialog('IsAdultDialog',
(session) => {
session.conversationData.isAdult = true;
if(session.conversationData.isFood) {
session.send('Check out these resources, hope they help! Let me know if you have more questions.');
session.send(getAdultFoodInfo());
delete session.conversationData.isFood;
}
session.endDialog();
}
).triggerAction({
matches: 'IsAdult'
})
bot.dialog('GetChildCareInfoDialog',
(session) => {
session.send("Here are some resources for affordable child care.")
session.endDialog();
}
).triggerAction({
matches: 'GetChildCareInfo'
})
bot.dialog('GetClothingInfoDialog',
(session) => {
session.send("Here are some resources about clothing.")
session.endDialog();
}
).triggerAction({
matches: 'GetClothingInfo'
})
bot.dialog('GetMentalHealthInfoDialog',
(session) => {
session.send("Here are some resources about mental health.")
session.endDialog();
}
).triggerAction({
matches: 'GetMentalHealthInfo'
})
bot.dialog('GetPetInfoDialog',
(session) => {
session.send("Here are some resources about help for your pet.")
session.endDialog();
}
).triggerAction({
matches: 'GetPetInfo'
})
bot.dialog('GetSportsInfoDialog',
(session) => {
session.send("Here are some resources about sports equipment and participation.")
session.send(getSportsInfo());
session.endDialog();
}
).triggerAction({
matches: 'GetSportsInfo'
})
bot.dialog('GetTutoringInfoDialog',
(session) => {
session.send("Here are some resources about tutoring.");
session.endDialog();
}
).triggerAction({
matches: 'GetTutoringInfo'
})
// Helpers
function infoAsAttachmentHero(info) {
return new builder.HeroCard()
.title(info.name)
.subtitle('%s', info.info)
.images([new builder.CardImage().url(info.image)])
.buttons([
new builder.CardAction()
.title('More details')
.type('openUrl')
.value(info.url)
]);
}
function getSportsInfo() {
return new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(infoSports.map(infoAsAttachmentHero));
}
function getStudentFoodInfo() {
return new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments([...infoFoodStudents, ...infoFood].map(infoAsAttachmentHero));
}
function getAdultFoodInfo() {
return new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(infoFood.map(infoAsAttachmentHero));
}
function getParentFoodInfo() {
return new builder.Message()
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments([...infoFoodParent, ...infoFood].map(infoAsAttachmentHero));
}
var infoFood = [
{ name:'The Greater Vancouver Food Bank',
info:'The Greater Vancouver Food Bank provides a 2-3 day food supplement to thousands of people each week by way of locations throughout the Greater Vancouver area.',
url: 'https://foodbank.bc.ca/find-help/',
image:'https://foodbank.bc.ca/wp-content/themes/foodbank/images/logo.png'
},
{
name:'The Door is Open',
info:'Soup and sandwich free lunch',
url:'http://www.thedoorisopen.ca/free-lunch-program/',
image:'http://www.thedoorisopen.ca/wp-content/uploads/2017/11/cropped-rcav-full_colour_reverse-300_md-rgb_digital.png'
},
{
name:'Carnegie Centre cafeteria and kitchen',
info:'The Carnegie Community Centre cafeteria is open seven days a week, 365 days a year. Meals are provided at an extremely low cost to assure that local low-income residents can readily access nutritious, fresh and affordable food.',
url:'https://vancouver.ca/parks-recreation-culture/carnegie-centre-cafeteria.aspx',
image:'https://vancouver.ca/images/cov/ui/covLogo.png'
}
];
var infoFoodParent = [
{
name:'SPFoodBank',
info:'Home delivered food hampers for single parents that cannot use their local foodbanks',
url:'http://www.spfoodbank.org/',
image:''
}
];
var infoFoodStudents = [
{ name:'Simon Fraser Student Society Food Bank',
info:'Facing hunger or serious financial pressures? Apply for and redeem a $25 food certificate up to 3 times per semester.',
url:'http://sfss.ca/services/general-office-services/food-bank-program/',
image:'http://sfss.ca/wp-content/themes/sfss/img/sfss-logo-small.png'
},
{
name:'The AMS Food Bank',
info:'The AMS Food Bank is an emergency food relief service for UBC students in need. We offer various non-perishable foods, personal hygiene supplies, budgeting tips and information on additional resources in and around Vancouver. ',
url:'http://www.ams.ubc.ca/student-services/food-bank/',
image:'https://media.licdn.com/dms/image/C4D0BAQES4IiirDR_rg/company-logo_200_200/0?e=2159024400&v=beta&t=cUxThl5Yi83iINU0Xe4KATELq-4X-18m9JFIhry1zkc'
},
{
name:'Weekend Fuelbag',
info:'They give students in need access to food on weekends so they can come to school ready to learn.',
url:'https://weekendfuelbag.ca/',
image:'http://vanhacks.com/img/logos/weekend-fuelbag-logo-white.png'
},
{
name:'Directions Youth Services',
info:'Directions Youth Services is a Vancouver based resource that provides support to at-risk, homeless, or street-involved youth and young adults under 25.',
url:'https://directionsyouthservices.ca/drop-in-centre/food-program/',
image:'http://directionsyouthservices.ca/wp-content/uploads/2016/06/DIRECTIONS-YS_RGB1.jpg'
}
];
var infoSports = [
{ name:'Athletics for Kids (A4K)',
info:'A4K’s overarching goal is to be there to assist any B.C. child in their dream of playing amateur sports. We want all kids to have the opportunity to play.',
url:'https://www.a4k.ca/',
},
{
name:'Vancouver Kidsport',
info:'KidSport™ was established by Sport BC in 1993 and is a community based sport charity. Since its inception in British Columbia, KidSport™ has grown to include national and provincial/territorial chapters operating across Canada. There are now more than 180 local community chapters that have raised in excess of $5 million dollars and provided a season of sport to more than 45,000 Canadian children in 65 different sports.',
url:'http://www.kidsportcanada.ca/british-columbia/vancouver/',
},
{
name:'Canadian Tire Jumpstart',
info:'Raising funds. Lifting spirits. Supporting dreams. Jumpstart is more than just about getting kids active. It’s about giving kids from families in financial need the same chance to participate as their neighbours, their classmates and their friends. Whether it’s the chance to try a new sport or to continue with a favourite one, no kid should be left out.',
url:'http://jumpstart.canadiantire.ca/en.html',
},
{
name:'Hockey Access Fund',
info:'The VMHA Hockey Access Fund was created in conjunction with the Britannia Community Centre to provide opportunity to those under the age of 18 without adequate financial means, the ability to access funds allowing them to participate in organized hockey within the Vancouver Minor Hockey Association.',
url:'https://www.vmha.com/wp-content/uploads/sites/885/2017/10/VMHA-Hockey-Access-Fund-Application-and-Information-.pdf',
}
];