-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
50 lines (41 loc) · 1.58 KB
/
index.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
"use strict";
require('dotenv').config();
let builder = require("botbuilder");
let restify = require('restify');
let authenticationService = require('./app/services/authenticationService');
let utils = require('./app/helpers/utils');
let connector = new builder.ChatConnector({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
let bot = new builder.UniversalBot(connector, session => session.endDialog("default_dialog"));
//serve the bot
let server = restify.createServer();
server.post('/api/messages', connector.listen());
server.listen(process.env.port || process.env.PORT || 3978, function () {
console.log('%s listening to %s', server.name, server.url);
});
server.use(restify.bodyParser());
server.use(restify.queryParser());
//authentication
bot.auth = authenticationService.initialize(server, bot);
//recognizers
utils.getFiles('./app/recognizers')
.map(file => Object.assign(file, { recognizer: require(file.path) }))
.forEach(r => bot.recognizer(r.recognizer));
//dialogs
utils.getFiles('./app/dialogs')
.map(file => Object.assign(file, { fx: require(file.path) }))
.forEach(dialog => dialog.fx(dialog.name, bot));
//events
utils.getFiles('./app/events')
.map(file => Object.assign(file, { fx: require(file.path) }))
.forEach(event => event.fx(event.name, bot));
//middleware
utils.getFiles('./app/middleware')
.map(file => require(file.path))
.forEach(mw => bot.use(mw));
//libraries
utils.getFiles('./app/libraries')
.map(file => require(file.path))
.forEach(library => bot.library(library.createLibrary()));