-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (61 loc) · 2.47 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
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
var builder = require('botbuilder');
var ctrl = require('./src/ctrl')
var restify = require('restify');
var text = require("./src/text.json");
var moment = require("moment");
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var bot = new builder.UniversalBot(connector, { persistConversationData: true });
server.post('/api/messages', connector.listen());
bot.beginDialogAction('hi', '/', { matches: /^\bhi\b|\bhello\b|\bhey\b|\bhallo\b/i });
bot.beginDialogAction('presentations', '/presentations', { matches: /^presentations/i });
bot.beginDialogAction('workshops', '/workshops', { matches: /^workshops/i });
bot.beginDialogAction('menu', '/menu', { matches: /^menu/i });
bot.beginDialogAction('info', '/menu', { matches: /^info/i });
bot.beginDialogAction('now', '/now', { matches: /^now/i });
bot.beginDialogAction('next', '/next', { matches: /^next/i });
bot.beginDialogAction('venue', '/venue', { matches: /^venue/i });
bot.beginDialogAction('afterparty', '/afterparty', { matches: /^party/i });
bot.endConversationAction('goodbye', text.bye, { matches: /^bye/i });
bot.dialog('/', function (session) {
session.sendTyping();
if (session.conversationData.firstRun === true) {
session.send(text.hi);
} else {
session.send(text.back);
}
session.beginDialog('/menu');
});
bot.dialog('/menu', function (session) {
ctrl.sendMenu(session, text.labels.menu);
});
bot.dialog('/presentations', function (session) {
ctrl.sendItems(session, "presentation", false, text.labels.presentations);
});
bot.dialog('/workshops', function (session) {
ctrl.sendItems(session, "workshop", false, text.labels.workshops);
});
bot.dialog('/now', function (session) {
ctrl.sendItems(session, null, true, text.labels.now);
});
bot.dialog('/next', function (session) {
ctrl.sendItems(session, null, false, text.labels.next);
});
bot.dialog('/venue', function (session) {
ctrl.sendVenue(session, text.labels.venue);
});
bot.dialog('/afterparty', function (session) {
ctrl.sendAfterparty(session, text.labels.afterparty);
});
bot.use({
botbuilder: function (session, callback) {
session.conversationData.firstRun = (session.conversationData.firstRun === undefined);
callback();
}
});