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 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'))