forked from microsoft/BotBuilder-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
61 lines (53 loc) · 2.16 KB
/
Copy pathapp.js
File metadata and controls
61 lines (53 loc) · 2.16 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
55
56
57
58
59
60
61
var builder = require('botbuilder');
var restify = require('restify');
// 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
});
const ChangePasswordOption = 'Change Password';
const ResetPasswordOption = 'Reset Password';
// Bot Storage: Here we register the state storage for your bot.
// Default store: volatile in-memory store - Only for prototyping!
// We provide adapters for Azure Table, CosmosDb, SQL Azure, or you can implement your own!
// For samples and documentation, see: https://github.com/Microsoft/BotBuilder-Azure
var inMemoryStorage = new builder.MemoryBotStorage();
var bot = new builder.UniversalBot(connector, [
(session) => {
builder.Prompts.choice(session,
'What do yo want to do today?',
[ChangePasswordOption, ResetPasswordOption],
{ listStyle: builder.ListStyle.button });
},
(session, result) => {
if (result.response) {
switch (result.response.entity) {
case ChangePasswordOption:
session.send('This functionality is not yet implemented! Try resetting your password.');
session.reset();
break;
case ResetPasswordOption:
session.beginDialog('resetPassword:/');
break;
}
} else {
session.send(`I am sorry but I didn't understand that. I need you to select one of the options below`);
}
},
(session, result) => {
if (result.resume) {
session.send('You identity was not verified and your password cannot be reset');
session.reset();
}
}
]).set('storage', inMemoryStorage); // Register in memory storage
//Sub-Dialogs
bot.library(require('./dialogs/reset-password'));
//Validators
bot.library(require('./validators'));
server.post('/api/messages', connector.listen());