From ff9c1f1dcff8a18180b86f2620311c1561c342c2 Mon Sep 17 00:00:00 2001 From: Michilis Date: Sat, 20 Dec 2025 02:38:56 +0000 Subject: [PATCH] Remove keyboard buttons for users in groups when pressed --- telegram_bot/src/index.ts | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/telegram_bot/src/index.ts b/telegram_bot/src/index.ts index eb1049e..5eb7689 100644 --- a/telegram_bot/src/index.ts +++ b/telegram_bot/src/index.ts @@ -223,17 +223,45 @@ bot.onText(/\/lottosettings/, async (msg) => { // TEXT MESSAGES // ═══════════════════════════════════════════════════════════════════════════ +// Keyboard button texts that should trigger keyboard removal in groups +const KEYBOARD_BUTTON_TEXTS = [ + '🎰 Upcoming Jackpot', + '🎟 Buy Tickets', + '🧾 My Tickets', + '🏆 My Wins', + '⚡ Lightning Address', + '⚙️ Settings', + 'ℹ️ Help', +]; + // Handle keyboard button presses (text messages) bot.on('message', async (msg) => { if (!msg.text || msg.text.startsWith('/')) return; if (!shouldProcessMessage(msg.message_id)) return; - // Ignore group messages for button handling - if (isGroupChat(msg)) return; - const text = msg.text.trim(); const userId = msg.from?.id; + // Handle keyboard button presses in groups - remove the keyboard for that user + if (isGroupChat(msg)) { + // Only trigger if the message matches an exact keyboard button text + if (KEYBOARD_BUTTON_TEXTS.includes(text)) { + try { + // Send a temporary message to remove the keyboard for this user only + const sentMessage = await bot.sendMessage(msg.chat.id, '⚡', { + reply_to_message_id: msg.message_id, + reply_markup: { remove_keyboard: true, selective: true }, + }); + // Delete the message immediately so nothing is visible in the group + await bot.deleteMessage(msg.chat.id, sentMessage.message_id); + } catch (error) { + // Silently fail - bot might not have delete permissions + logger.error('Error removing keyboard in group', { error, chatId: msg.chat.id, userId }); + } + } + return; + } + if (!userId) return; // Handle menu button presses