feat: сохранение названия чата в историю.

вывод списка чатов в виде id.
This commit is contained in:
Vufer 2025-06-30 21:42:55 +03:00
parent f8b98de8b0
commit 4fe93cac7c

17
bot.js
View File

@ -39,6 +39,13 @@ class TelegramHistoryBot {
return false return false
} }
} }
getUniqueChatIds() {
const ids = new Set();
for (const msg of this.history) {
ids.add(msg.chat_id);
}
return Array.from(ids);
}
async init() { async init() {
try { try {
@ -126,6 +133,15 @@ class TelegramHistoryBot {
}); });
this.bot.command('getchats', 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 chatIds = this.getUniqueChatIds();
await ctx.reply(JSON.stringify(chatIds))
});
// Команды суммаризации - должны быть ДО обработки обычных сообщений // Команды суммаризации - должны быть ДО обработки обычных сообщений
// this.bot.command('summary_day', async (ctx) => { // this.bot.command('summary_day', async (ctx) => {
// // if (!this.isAdmin(ctx)) { // // if (!this.isAdmin(ctx)) {
@ -214,6 +230,7 @@ class TelegramHistoryBot {
id: this.generateUniqueId(), id: this.generateUniqueId(),
telegram_message_id: msg.message_id, telegram_message_id: msg.message_id,
chat_id: msg.chat.id, chat_id: msg.chat.id,
chat_title: msg.chat.title || null,
user_id: msg.from.id, user_id: msg.from.id,
username: msg.from.username || null, username: msg.from.username || null,
first_name: msg.from.first_name || null, first_name: msg.from.first_name || null,