fixed code
All checks were successful
build / build (push) Successful in 29s

This commit is contained in:
cheetah 2025-04-05 13:37:10 +02:00
parent 5ed02466bc
commit 3eb4f8da70

View file

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