-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (47 loc) · 1.25 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
51
52
53
54
55
'use strict'
const Trailpack = require('trailpack')
const routes = require('./lib/routes')
const _ = require('lodash')
module.exports = class ChatbotTrailpack extends Trailpack {
/**
* Check if trailpack-cache is installed
*/
validate() {
if (!this.app.packs.cache) {
return Promise.reject(
new Error('trailpack-cache need to be installed in order to make chatbot working')
)
}
if (!this.app.config.chatbot) {
return Promise.reject(
new Error('config.chatbot doesn\'t exist, please correct this')
)
}
}
/**
* Compile route with prefix if needed
*/
configure() {
const prefix = _.get(this.app.config, 'chatbot.prefix') || _.get(this.app.config, 'footprints.prefix')
const routerUtil = this.app.packs.router.util
if (prefix) {
routes.forEach(route => {
route.path = prefix + route.path
})
}
this.app.config.routes = routerUtil.mergeRoutes(routes, this.app.config.routes)
}
/**
* Initialize bots
*/
initialize() {
return this.app.services.ChatBotService.init(this.app.config.chatbot.bots)
}
constructor(app) {
super(app, {
config: require('./config'),
api: require('./api'),
pkg: require('./package')
})
}
}