import TelegramBot from 'node-telegram-bot-api'; import dotenv from 'dotenv'; // Load environment variables dotenv.config(); // Temporary script to get group chat ID and topic IDs // Run this once to get the IDs you need for monitoring setup const token = process.env.TELEGRAM_BOT_TOKEN; if (!token) { console.error('āŒ TELEGRAM_BOT_TOKEN not found in environment variables'); process.exit(1); } const bot = new TelegramBot(token, { polling: true }); console.log('šŸ¤– Bot started! Add me to your supergroup and I\'ll help you get the IDs...\n'); // Listen for messages to get chat ID bot.on('message', (msg) => { const chatId = msg.chat.id; const chatType = msg.chat.type; const chatTitle = msg.chat.title; if (chatType === 'supergroup') { console.log('šŸ“Š SUPERGROUP DETECTED:'); console.log(` Chat ID: ${chatId}`); console.log(` Title: ${chatTitle}`); console.log(` Type: ${chatType}\n`); // Check if message is in a topic if (msg.message_thread_id) { console.log('šŸ“ TOPIC MESSAGE DETECTED:'); console.log(` Topic ID: ${msg.message_thread_id}`); console.log(` Message: ${msg.text || '[Non-text message]'}`); console.log(` From: ${msg.from?.first_name || 'Unknown'}\n`); } // Send a test message to confirm bot can send messages bot.sendMessage(chatId, `āœ… Bot connected successfully!\n\n` + `šŸ“Š Group Info:\n` + `• Chat ID: \`${chatId}\`\n` + `• Title: ${chatTitle}\n` + `• Type: ${chatType}\n\n` + `šŸ“ To get topic IDs:\n` + `1. Create topics in this group\n` + `2. Send a message in each topic\n` + `3. Check the console output for topic IDs`, { parse_mode: 'Markdown' } ).catch(err => { console.error('āŒ Failed to send message to group:', err.message); console.log('šŸ’” Make sure the bot has permission to send messages in the group'); }); } else if (chatType === 'private') { console.log(`šŸ’¬ Private message from ${msg.from?.first_name}: ${msg.text}`); } else { console.log(`šŸ“± Message from ${chatType}: ${chatTitle || 'Unknown'} (ID: ${chatId})`); } }); // Listen for errors bot.on('error', (error) => { console.error('āŒ Bot error:', error.message); }); // Graceful shutdown process.on('SIGINT', () => { console.log('\nšŸ‘‹ Shutting down bot...'); bot.stopPolling(); process.exit(0); }); console.log('šŸ“‹ Instructions:'); console.log('1. Add this bot to your supergroup as admin'); console.log('2. Enable topics in the group settings'); console.log('3. Create the monitoring topics'); console.log('4. Send a message in each topic'); console.log('5. Copy the Chat ID and Topic IDs from the output'); console.log('6. Press Ctrl+C to stop this script\n');