feat: сохранение названия чата в историю.
вывод списка чатов в виде id.
This commit is contained in:
parent
f8b98de8b0
commit
4fe93cac7c
17
bot.js
17
bot.js
@ -39,6 +39,13 @@ class TelegramHistoryBot {
|
||||
return false
|
||||
}
|
||||
}
|
||||
getUniqueChatIds() {
|
||||
const ids = new Set();
|
||||
for (const msg of this.history) {
|
||||
ids.add(msg.chat_id);
|
||||
}
|
||||
return Array.from(ids);
|
||||
}
|
||||
|
||||
async init() {
|
||||
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) => {
|
||||
// // if (!this.isAdmin(ctx)) {
|
||||
@ -214,6 +230,7 @@ class TelegramHistoryBot {
|
||||
id: this.generateUniqueId(),
|
||||
telegram_message_id: msg.message_id,
|
||||
chat_id: msg.chat.id,
|
||||
chat_title: msg.chat.title || null,
|
||||
user_id: msg.from.id,
|
||||
username: msg.from.username || null,
|
||||
first_name: msg.from.first_name || null,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user