feat: /broadcast рассылка сообщения по всем чатам

This commit is contained in:
Vufer 2025-06-30 22:10:09 +03:00
parent 6d7bce6a6f
commit 11801add49

22
bot.js
View File

@ -155,6 +155,28 @@ class TelegramHistoryBot {
.join('\n');
await ctx.reply(message)
});
this.bot.command('broadcast', async (ctx) => {
if (ctx.message.chat.id!==Number(process.env.ADMIN_CHAT_ID)) {
logger.warn(JSON.stringify(ctx.message))
logger.warn('Попытка вызова бродкаста из стороннего чата. Пользователь ' + JSON.stringify(ctx.message.from))
return
}
const fullText = ctx.message.text || '';
const text = fullText.replace(/^\/broadcast\s*/, '').trim();
if (!text) {
return ctx.reply('❗️ Пожалуйста, укажите текст для рассылки после команды /broadcast');
}
logger.info('📊 Получена команда /broadcast с запросом:' + text)
const chatList= this.getUniqueChatIds()
for (const chat of chatList) {
try {
await this.bot.telegram.sendMessage(chat.chat_id, text);
logger.info(`✅ Сообщение отправлено в чат ${chat.title} (${chat.chat_id})`);
} catch (error) {
logger.error(`❌ Ошибка при отправке в чат ${chat.title} (${chat.chat_id}):`, error);
}
}
})
// Команды суммаризации - должны быть ДО обработки обычных сообщений
// this.bot.command('summary_day', async (ctx) => {
// // if (!this.isAdmin(ctx)) {