-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
57 lines (48 loc) · 1.69 KB
/
bot.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
import './config'
import logger from './services/logger'
import luis from 'botkit-middleware-luis'
import webserver from './services/webserver'
import http from './services/http'
import qnaMaker from './services/qnaMaker'
import * as skills from './skills/*'
import * as middleware from './middleware/*'
const info = logger('main', 'info')
const error = logger('main', 'error')
export default function(controller, bot) {
bot = bot || controller.spawn({
appId: process.env.MS_APP_ID,
appPassword: process.env.MS_APP_PASSWORD,
require_delivery: false
})
const luisOptions = {
serviceUri: process.env.LUIS_URI,
minThreshold: 0.1
}
// create the webserver
webserver(controller, bot)
.then(app => http(app, controller))
.catch(err => error(err))
// Start the bot
controller.startTicking()
// activate middleware
Object.values(middleware).forEach(fn => fn(controller))
// add LUIS middleware
controller.middleware.receive.use(luis.middleware.receive(luisOptions))
// activate the bots skills
Object.values(skills).forEach(definitions => {
definitions.forEach(skill => {
if (skill.hears) {
if (skill.bypassLuis) {
controller.hears(skill.hears, 'message_received', (bot, message) => skill.response(bot, message, controller))
} else {
controller.hears(skill.hears, 'message_received', luis.middleware.hereIntent(), (bot, message) => skill.response(bot, message, controller))
}
} else if (skill.on) {
controller.on(skill.on, (bot, message) => skill.response(bot, message, controller))
}
})
})
// default response
controller.hears('.*', 'message_received', qnaMaker)
info('bot online')
}