-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (48 loc) · 1.42 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
var restify = require('restify');
var builder = require('botbuilder');
require('dotenv').load();
//=========================================================
// 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
if (process.env.DEBUG) {
var connector = new builder.ConsoleConnector().listen();
} else {
var connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
}
var bot = new builder.UniversalBot(connector);
if (! process.env.DEBUG) {
server.post('/api/messages', connector.listen());
}
//=========================================================
// Bots Dialogs
//=========================================================
bot.dialog('/', [
function (session, args, next) {
if (! session.userData.name) {
session.beginDialog('/profile');
} else {
next();
}
},
function (session, results) {
session.send('Hello %s!', session.userData.name);
}
]);
bot.dialog('/profile', [
function (session) {
builder.Prompts.text(session, 'Hi! What is your name?');
},
function (session, results) {
session.userData.name = results.response;
session.endDialog();
}
]);