diff --git a/index.js b/index.js index 59694b3..7a28435 100644 --- a/index.js +++ b/index.js @@ -14,9 +14,10 @@ const io = require("socket.io-client") const axios = require('axios') const fs = require('fs') const socket = io(new URL(config.pager.url).origin) +const enableBot = config.bottoken.length > 5 -const bot = new Telegraf(config.bottoken || '1234567890:AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA') -bot.start((ctx) => ctx.reply('Welcome, write me a message')) +const bot = enableBot ? new Telegraf(config.bottoken) : {} +if (enableBot) bot.start((ctx) => ctx.reply('Welcome, write me a message')) let assoc = {} function filter(txt) { @@ -52,19 +53,20 @@ socket.on('msgmgr:event', (eventType, eventData) => { } break; } }) -bot.on('message', (ctx) => { - if (!ctx.update.message.text) return ctx.reply("not a textmessage") -// if (!ctx.update.message.type) - console.log(ctx.update.message.from) - const preview = `Preview: ${ filter(ctx.update.message.from.first_name) }:${ filter(ctx.update.message.text) }` - console.log(preview) - ctx.reply(preview, Markup.inlineKeyboard( - config.deliveryModes.map((deliveryModeConfig, index) => - Markup.button.callback(deliveryModeConfig.name, 'deliveryMode-' + index) - ) - )) -}) - +if (enableBot) { + bot.on('message', (ctx) => { + if (!ctx.update.message.text) return ctx.reply("not a textmessage") + // if (!ctx.update.message.type) + console.log(ctx.update.message.from) + const preview = `Preview: ${ filter(ctx.update.message.from.first_name) }:${ filter(ctx.update.message.text) }` + console.log(preview) + ctx.reply(preview, Markup.inlineKeyboard( + config.deliveryModes.map((deliveryModeConfig, index) => + Markup.button.callback(deliveryModeConfig.name, 'deliveryMode-' + index) + ) + )) + }) +} for (let deliveryModeIndex in config.deliveryModes) { bot.action('deliveryMode-' + deliveryModeIndex, async (ctx) => { const origText = ctx.update.callback_query.message.text.substring(8+1) @@ -94,7 +96,7 @@ for (let deliveryModeIndex in config.deliveryModes) { await ctx.editMessageText(assoc[msgId].newText) }) } -bot.launch() +if (enableBot) bot.launch() // Enable graceful stop process.once('SIGINT', () => bot.stop('SIGINT'))