-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
37 lines (28 loc) · 886 Bytes
/
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
require('dotenv').config()
const { midnabot } = require('./bots/midnabot')
/** Start bots in development mode (polling) */
const development = () => {
process.stdout.write('Bots starting in development mode...\n')
midnabot.launch()
}
/** Start bots in production mode (webhook) */
const production = async () => {
const app = require('express')()
const domain = process.env.SERVICE_URL
const port = Number(process.env.SERVICE_PORT)
app.use(await midnabot.createWebhook({ domain }))
app.get('/', (req, res) => res.send('OK'))
app.listen(port, () => {
process.stdout.write('Bots starting in production mode...\n')
})
}
process.env.NODE_ENV === 'production'
? (async () => await production())()
: development()
/** Graceful stop */
process.once('SIGINT', () => {
midnabot.stop('SIGINT')
})
process.once('SIGTERM', () => {
midnabot.stop('SIGTERM')
})