diff --git a/bot.js b/bot.js index a61ddc1..6c444b6 100644 --- a/bot.js +++ b/bot.js @@ -40,11 +40,21 @@ class TelegramHistoryBot { } } getUniqueChatIds() { - const ids = new Set(); + const chatMap = new Map(); + for (const msg of this.history) { - ids.add(msg.chat_id); + const current = chatMap.get(msg.chat_id); + if (!current || new Date(msg.timestamp) > new Date(current.timestamp)) { + chatMap.set(msg.chat_id, { + chat_id: msg.chat_id, + title: msg.chat_title || `(${msg.chat_id})`, + timestamp: msg.timestamp + }); + } } - return Array.from(ids); + + // Преобразуем Map в массив, возвращаем только chat_id и title + return Array.from(chatMap.values()).map(({ chat_id, title }) => ({ chat_id, title })) } async init() {