This commit is contained in:
parent
5ed02466bc
commit
3eb4f8da70
1 changed files with 18 additions and 16 deletions
34
index.js
34
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'))
|
||||
|
|
Loading…
Add table
Reference in a new issue