-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhellobot.js
123 lines (99 loc) · 4.78 KB
/
hellobot.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
var builder = require('botbuilder');
var restify = require('restify');
var search = require('./search.js');
var specialChars = require('underscore');
var connector = new builder.ChatConnector();
var bot = new builder.UniversalBot(connector);
var types = ['Information session', 'Workshop', 'Lecture', 'Conference', 'Seminar', 'Open house', 'Reception', 'Performance', 'Thesis defence', 'Reunion', 'Meeting']
// LUIS connection
var recognizer = new builder.LuisRecognizer("https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/deecd678-4dca-4736-bc93-f3982e1ae346?subscription-key=8a9b1636e26d4a7a8788c900a0aa98e6&verbose=true");
bot.recognizer(recognizer);
var dialog = new builder.IntentDialog({recognizers:[recognizer]});
bot.dialog('/',dialog);
dialog.matches('Greeting', [
// Search input
function (session,result, args) {
// if (session.message.text.toLowerCase() == 'search') {
session.send("Hey! I'm the WatsLit Bot! I know everything about what's lit at UWaterloo! To start off, here are some trending events: ");
var query = result.response;
search.searchEvents(null,null, "Workshop", function (response) {
session.dialogData.property = null;
// display the cards
var cards = [];
for(var i=0; i<10; ++i){
var datetime =new Date( Date.parse(response[i].times[0].start));
console.log(response[i]);
cards.push(
new builder.HeroCard(session)
.title(specialChars.unescape(response[i].title).replace("'","'"))
.subtitle("This program starts at: " + datetime)
.text('This event is run by: ' + response[i].site_name)
.images([
builder.CardImage.create(session, 'https://raw.githubusercontent.com/PragashSiva/bart/master/Null-Photo-Image.jpg')
])
.buttons([
builder.CardAction.openUrl(session, response[i].link , 'Learn More'),
builder.CardAction.imBack(session, response[i].id, "🔥")
])
);
}
// create reply with Carousel AttachmentLayout
var reply = new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(cards);
session.send(reply);
builder.Prompts.text(session, "Try a type of event (e.g. workshops, gala)");
session.endDialog();
})
}
]);
dialog.matches('Event Search',[
// Create the carousel
function (session,args, next) {
console.log(args.entities[1].resolution.date);
var time = new Date(args.entities[1].resolution.date);
time = time.toISOString();
console.log(time);
var query = args.entities[0].type;
builder.Prompts.text(session, "Here's what I found:");
search.searchEvents(time, "2017-03-26T09:45:00-04:00", query, function (response) {
session.dialogData.property = null;
var cards = []; //getCardsAttachments();
for(var i=0; i<10; ++i){
var datetime =new Date( Date.parse(response[i].times[0].start));
console.log(response[i]);
cards.push(
new builder.HeroCard(session)
.title(specialChars.unescape(response[i].title).replace("'", "'"))
.subtitle("This program starts at: " + datetime)
.text('This event is run by: ' + response[i].site_name)
.images([
builder.CardImage.create(session, 'https://raw.githubusercontent.com/PragashSiva/bart/master/Null-Photo-Image.jpg')
])
.buttons([
builder.CardAction.openUrl(session, response[i].link , 'Learn More'),
builder.CardAction.imBack(session, response[i].id, "🔥")
])
// .tap(new builder.CardAction.imBack(session, response[i].id, response[i].title))
);
}
// create reply with Carousel AttachmentLayout
var reply = new builder.Message(session)
.attachmentLayout(builder.AttachmentLayout.carousel)
.attachments(cards);
session.send(reply);
session.endDialog();
})
}
]);
dialog.matches('Help',[
// Create the carousel
function (session, result, next) {
builder.Prompts.choice("Here's a full list of options.",types)
}
]);
var server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
server.post('/api/messages', connector.listen());