-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.js
102 lines (87 loc) · 2.89 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
var restify = require('restify');
var builder = require('botbuilder');
var env = require('./env.js');
var username; //gabrielle_crevecoeur
var quiz = require('./api.js');
var index = 0;
(function () {
if (username)
quiz.GetSets(username); // I will invoke myself
})();
//=========================================================
// Bot Setup
//=========================================================
// 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 bot
var connector = new builder.ChatConnector({
appId: process.env.APP_ID,
appPassword: process.env.APP_PASS
});
var bot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
//=========================================================
// Bots Dialogs
//=========================================================
bot.dialog('/',
function (session) {
session.send("Hello! Welcome to the Mhacks Quiz Bot. Would you like to study today?")
session.beginDialog('/user');
});
bot.dialog('/user', new builder.IntentDialog()
.matches(/^yes/i, [
function (session) {
// setTimeout(function () {
if (username)
session.beginDialog('/subject')
else {
builder.Prompts.text(session, "What is your quizlet username?")
}
// }, 3000)
},
function (session, results) {
quiz.GetSets(results.response);
session.beginDialog('/subject')
}])
.matches(/^no/i, function(session){
session.send("Ok see ya later!")
session.endConversation;
}));
bot.dialog('/subject', [
function (session) {
setTimeout(function(){
builder.Prompts.text(session, "What study set would you like today?" + quiz.Sets);
}, 2000)
},
function (session, results) {
quiz.GetTerms(results.response);
session.send("Ok! I got your flashcards! Send 'ready' to begin. Send 'flip' for definition. Send 'next' for the next card. Send 'exit' when you are done")
session.beginDialog('/study')
}]
);
bot.dialog('/study', new builder.IntentDialog()
.matches(/^ready/i, [
function (session) {
session.send(quiz.Terms[index])
}])
.matches(/^flip/i, [
function (session) {
session.send(quiz.Def[index])
}]
)
.matches(/^next/i, [
function (session) {
if (++index == quiz.Terms.length)
session.send("You are all out of cards! Hope you had fun studying! :)")
else
session.send(quiz.Terms[index])
}])
.matches(/^exit/i, [
function (session) {
session.send("Hope you had fun studying. See ya later :)")
}]
)
);