-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
92 lines (84 loc) · 3.01 KB
/
server.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
'use strict';
var restify = require('restify'),
builder = require('botbuilder'),
bot = require('./bot'),
netshoes = require('./netshoes'),
nlp = require('./nlp');
// 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.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
var apiBot = new builder.UniversalBot(connector);
server.post('/api/messages', connector.listen());
//=========================================================
// Bots Dialogs
//=========================================================
apiBot.dialog('/', new builder.IntentDialog()
.matches(nlp.greetings(), function (session) {
dialogInterceptor(session, bot.sendGreetings(session));
})
.matches(nlp.funny(), function (session) {
dialogInterceptor(session, bot.sendFunny(session));
})
.matches(nlp.help(), function (session) {
dialogInterceptor(session, bot.help(session));
})
.matches(nlp.thanks(), function (session) {
dialogInterceptor(session, bot.thanks(session));
})
.matches(nlp.rude(), function (session) {
bot.rude(session);
})
.matches(nlp.yesNo(), function (session) {
dialogInterceptor(session, bot.yesNo(session));
})
.matches(nlp.howTheTestsAreGoingOn(), function (session) {
dialogInterceptor(session, bot.howTheTestsAreGoingOn(session));
})
.matches(nlp.winnerTest(), function (session) {
dialogInterceptor(session, bot.winnerTest(session));
})
.matches(nlp.howToBuild(), function (session) {
dialogInterceptor(session, bot.howToBuild(session));
})
.matches(nlp.listLindTests(), function (session) {
dialogInterceptor(session, netshoes.processLindRequest(session));
})
.matches(nlp.lindGenerateURL(), function (session) {
dialogInterceptor(session, netshoes.generateLindURL(session));
})
.matches(nlp.lindAudience(), function (session) {
dialogInterceptor(session, netshoes.getLindAudience(session));
})
.matches(nlp.lindClearCache(), function (session) {
dialogInterceptor(session, netshoes.clearCache(session));
})
.matches(nlp.lindStatusCache(), function (session) {
dialogInterceptor(session, netshoes.cacheStatus(session));
})
.onDefault(function (session) {
dialogInterceptor(session, bot.sendCommonMessage(session));
})
);
apiBot.dialog('/profile', [
function (session) {
builder.Prompts.text(session, "Hi! I'm **LindBot**. A Bot for helping in common Lind tasks. What is your name?");
},
function (session, results) {
session.userData.name = results.response;
bot.sendCommonMessage(session, results);
}
]);
function dialogInterceptor(session, callback) {
if(!session.userData.name) {
session.beginDialog('/profile');
} else {
callback;
}
}