Yaltopia-Homes-TGClient/docs/GET_SUPERGROUP_IDS.md

2.0 KiB

🔍 Get Supergroup Chat ID & Topic ID

Simple script to get supergroup chat IDs and topic IDs for local development.

📋 Quick Script

Create quick-chat-info.js in your project root:

#!/usr/bin/env node
require('dotenv').config();
const TelegramBot = require('node-telegram-bot-api');

console.log('🔍 Supergroup Chat ID & Topic ID Getter');
console.log('Add your bot to supergroup and send a message...\n');

const botToken = process.env.TELEGRAM_BOT_TOKEN;
if (!botToken || botToken === 'YOUR_BOT_TOKEN_HERE') {
    console.log('❌ Set TELEGRAM_BOT_TOKEN in .env file');
    process.exit(1);
}

const bot = new TelegramBot(botToken, { polling: true });

bot.on('message', (msg) => {
    if (msg.chat.type === 'supergroup') {
        console.log(`📋 Supergroup: ${msg.chat.title}`);
        console.log(`Chat ID: ${msg.chat.id}`);
        
        if (msg.message_thread_id) {
            console.log(`Topic ID: ${msg.message_thread_id}`);
            console.log(`\nFor .env: ADMIN_CHAT_IDS=${msg.chat.id}`);
            console.log(`For .env: MONITORING_TOPIC_ID=${msg.message_thread_id}\n`);
        } else {
            console.log(`\nFor .env: ADMIN_CHAT_IDS=${msg.chat.id}\n`);
        }
    }
});

process.on('SIGINT', () => {
    console.log('\n👋 Done!');
    process.exit(0);
});

🚀 Usage

  1. Set bot token in .env file
  2. Add bot to supergroup as admin
  3. Run script: node quick-chat-info.js
  4. Send message in supergroup (or topic)
  5. Copy IDs to .env file
  6. Press Ctrl+C to stop

🪟 Windows Batch File

Create get-chat-info.bat:

@echo off
echo 🔍 Getting Supergroup Chat ID and Topic ID
echo Add your bot to supergroup and send a message...
echo.
node quick-chat-info.js
pause

📋 Example Output

🔍 Supergroup Chat ID & Topic ID Getter
Add your bot to supergroup and send a message...

📋 Supergroup: Yaltipia Admin Chat
Chat ID: -1001234567890
Topic ID: 5

For .env: ADMIN_CHAT_IDS=-1001234567890
For .env: MONITORING_TOPIC_ID=5

Simple and focused! 🎯