forked from fuselabs/echobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
54 lines (48 loc) · 1.55 KB
/
Copy pathserver.js
File metadata and controls
54 lines (48 loc) · 1.55 KB
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
var restify = require('restify');
var builder = require('botbuilder');
// Get secrets from server environment
var botConnectorOptions = {
appId: process.env.BOTFRAMEWORK_APPID,
appSecret: process.env.BOTFRAMEWORK_APPSECRET
};
// Create bot
var bot = new builder.BotConnectorBot(botConnectorOptions);
bot.add('/', [
function (session, args, next) {
if (!session.userData.name || !session.userData.human) {
session.beginDialog('/profile');
}
else {
next();
}
},
function (session, results) {
session.send('Hello ' + session.userData.name +", it is " + session.userData.human + " that you are a human.");
}
]);
bot.add('/profile', [
function (session) {
builder.Prompts.text(session, "Hi, what is your name?");
},
function (session, nameResults) {
session.userData.name = nameResults.response;
builder.Prompts.confirm(session, "You are a human, right " + session.userData.name + "?");
},
function (session, humanResults) {
// Not working atm...
session.userData.human = humanResults.response;
session.endDialog();
}
]);
// Setup Restify Server
var server = restify.createServer();
// Handle Bot Framework messages
server.post('/api/messages', bot.verifyBotFramework(), bot.listen());
// Serve a static web page
server.get(/.*/, restify.serveStatic({
'directory': '.',
'default': 'index.html'
}));
server.listen(process.env.port || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});