-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.ts
43 lines (39 loc) · 1.36 KB
/
app.ts
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
import * as restify from 'restify';
import * as builder from 'botbuilder';
//=========================================================
// Bot Setup
//=========================================================
// Setup Restify Server
let server = restify.createServer();
server.listen(process.env.port || process.env.PORT || 3978, () => {
console.log(`${server.name} listening to ${server.url}`);
});
// Create chat bot
let connector = new builder.ConsoleConnector().listen();
let bot = new builder.UniversalBot(connector);
//=========================================================
// Bots Dialogs
//=========================================================
bot.dialog('/', [
(session) => {
builder.Prompts.text(session, 'Hi! What is your name?');
},
(session, results) => {
session.dialogData.name = results.response;
session.send(`Hello ${session.dialogData.name}`);
session.beginDialog('/askAge', session.dialogData.name);
},
(session) => {
session.endDialog('Goodbye !');
}
]);
bot.dialog('/askAge', [
(session, args, next) => {
session.dialogData.name = args || {};
builder.Prompts.text(session, `${session.dialogData.name} how old are you ?`);
},
(session, results) => {
session.send(`${session.dialogData.name} you're ${results.response}`);
session.endDialog();
}
]);