Skip to content

Commit

Permalink
web hook
Browse files Browse the repository at this point in the history
  • Loading branch information
derhuerst committed Mar 20, 2018
1 parent b1cea30 commit 3746ab5
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

const path = require('path')
const Bot = require('telegraf')
const url = require('url')

const logging = require('./lib/logging')
const session = require('./lib/session')
Expand Down Expand Up @@ -42,4 +43,29 @@ bot.use((ctx, next) => {
return handler(ctx, next)
})

bot.startPolling() // todo: web hook
if (process.env.NODE_ENV === 'dev') {
bot.startPolling()
} else {
const WEB_HOOK_HOST = process.env.WEB_HOOK_HOST
if (!WEB_HOOK_HOST) {
console.error('Missing WEB_HOOK_HOST env var.')
process.exit(1)
}
const WEB_HOOK_PATH = process.env.WEB_HOOK_PATH
if (!WEB_HOOK_PATH) {
console.error('Missing WEB_HOOK_PATH env var.')
process.exit(1)
}
const WEB_HOOK_PORT = process.env.WEB_HOOK_PORT && parseInt(process.env.WEB_HOOK_PORT)
if (!WEB_HOOK_PORT) {
console.error('Missing WEB_HOOK_PORT env var.')
process.exit(1)
}

bot.telegram.setWebhook(url.format({
protocol: 'https',
host: WEB_HOOK_HOST,
pathname: WEB_HOOK_PATH
}))
bot.startWebhook(WEB_HOOK_PATH, null, WEB_HOOK_PORT)
}

0 comments on commit 3746ab5

Please sign in to comment.