-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
57 lines (46 loc) · 1.38 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 Botkit's core features
const { Botkit } = require('botkit')
const { BotkitCMSHelper } = require('botkit-plugin-cms')
// Import a platform-specific adapter for botframework.
const { MongoDbStorage } = require('botbuilder-storage-mongodb')
// Load process.env values from .env file
require('dotenv').config()
let storage = null
if (process.env.MONGO_URI) {
storage = mongoStorage = new MongoDbStorage({
url: process.env.MONGO_URI,
})
}
const controller = new Botkit({
debug: true,
webhook_uri: '/api/messages',
adapterConfig: {
appId: process.env.APP_ID,
appPassword: process.env.APP_PASSWORD,
},
storage,
})
if (process.env.cms_uri) {
controller.usePlugin(
new BotkitCMSHelper({
cms_uri: process.env.cms_uri,
token: process.env.cms_token,
}),
)
}
// Once the bot has booted up its internal services, you can use them to do stuff.
controller.ready(() => {
// load traditional developer-created local custom feature modules
controller.loadModules(__dirname + '/features')
/* catch-all that uses the CMS to trigger dialogs */
if (controller.plugins.cms) {
controller.on('message,direct_message', async (bot, message) => {
let results = false
results = await controller.plugins.cms.testTrigger(bot, message)
if (results !== false) {
// do not continue middleware!
return false
}
})
}
})