forked from telegraf/micro-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
32 lines (29 loc) · 1.07 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
const Telegraf = require('telegraf')
const Stage = require('telegraf/stage')
const Scene = require('telegraf/scenes/base')
const WizardScene = require('telegraf/scenes/wizard')
const defaultInit = () => Promise.resolve()
const defaultCb = (req, res) => {
res.statusCode = 404
res.end()
}
function start ({ token, domain, hookPath, botModule, port, host, silent }) {
const webhook = typeof domain === 'string' || typeof hookPath === 'string'
? {
domain,
hookPath,
port,
host,
tlsOptions: botModule.tlsOptions,
cb: botModule.server || botModule.requestHandler || defaultCb
}
: null
const bot = new Telegraf(token, botModule.options)
const init = botModule.init || botModule.initialize || defaultInit
bot.catch((err) => console.error('μ-bot: Unhandled error', err))
bot.use(botModule.bot || botModule.botHandler || botModule)
return init(bot)
.then(() => bot.launch({ webhook }))
.then(() => !silent && console.log(`μ-bot: Bot started`))
}
module.exports = Object.assign(Telegraf, { Stage, Scene, WizardScene, start: start })