-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (49 loc) · 1.54 KB
/
Copy pathapp.js
File metadata and controls
55 lines (49 loc) · 1.54 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
var restify = require('restify');
var builder = require('botbuilder');
var botbuilder_mongo=require('botbuilder-mongodb')
var server = restify.createServer();
//change port number here
server.listen(process.env.port || process.env.PORT || 3980, function () {
console.log('%s listening to %s', server.name, server.url);
});
// Create chat bot
var connector = new builder.ChatConnector({
appId:" ",//pass here your's app id
appPassword:" "//pass here your's app password
});
// Listen for messages from users
server.post('/api/messages', connector.listen());
//Store session and context into mnongodb
const mongoOptions = {
ip: '127.0.0.1',
port: '27017',
database: 'BotStorage',
collection: 'ContextData',
username: '',
password: '',
queryString: ''
}
mongoStorage=botbuilder_mongo.GetMongoDBLayer(mongoOptions)
var bot = new builder.UniversalBot(connector).set('storage', mongoStorage);//set your storage here
bot.use(builder.Middleware.dialogVersion({ version: 3.0, resetCommand: /^reset/i }));
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();
}
]);