3.7 KiB
3.7 KiB
📱 How to Get Chat ID and Topic ID for Telegram Bot Monitoring
This guide will help you find your Chat ID and Topic ID for setting up Telegram bot monitoring notifications.
🎯 What You Need
- A Telegram account
- Access to create a bot or use an existing bot
- A group chat or supergroup where you want to receive notifications
📋 Step-by-Step Guide
1. Create or Access Your Bot
If you don't have a bot yet:
- Open Telegram and search for
@BotFather - Start a chat with BotFather
- Send
/newbotcommand - Follow the instructions to create your bot
- Save the Bot Token (you'll need this for your
.envfile)
2. Get Your Chat ID
Method 1: Using @userinfobot (Easiest)
- Search for
@userinfobotin Telegram - Start a chat and send any message
- The bot will reply with your Chat ID
Method 2: Using Telegram Web API
- Send a message to your bot
- Open this URL in your browser (replace
YOUR_BOT_TOKENwith your actual bot token):https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates - Look for the
"chat":{"id":field in the response - The number after
"id":is your Chat ID
Method 3: For Group Chats
- Add your bot to the group
- Send a message in the group
- Use the same API URL as Method 2
- Look for the chat object with
"type":"group"or"type":"supergroup" - The
"id"field will be your Group Chat ID (usually negative number)
3. Get Your Topic ID (For Supergroups with Topics)
If you're using a supergroup with topics enabled:
- Create or open the topic where you want notifications
- Send a message in that specific topic
- Use the API URL from Method 2 above
- Look for
"message_thread_id"in the response - This number is your Topic ID
Alternative Method for Topic ID:
- Right-click on a message in the topic
- Select "Copy Message Link"
- The URL will look like:
https://t.me/c/XXXXXXXXX/YYYY/ZZZZ - The
YYYYnumber is your Topic ID
🔧 Configuration
Once you have your IDs, add them to your .env file:
# Bot Configuration
TELEGRAM_BOT_TOKEN=your_bot_token_here
# Chat Configuration
TELEGRAM_CHAT_ID=your_chat_id_here
# Topic Configuration (optional - only for supergroups with topics)
TELEGRAM_TOPIC_ID=your_topic_id_here
✅ Testing Your Configuration
You can test if your configuration works by running:
node scripts/test-startup-notification.js
This will send a test message to verify your Chat ID and Topic ID are correct.
🔍 Troubleshooting
Common Issues:
Bot can't send messages to group:
- Make sure the bot is added to the group
- Ensure the bot has permission to send messages
- For channels, make sure the bot is an admin
Wrong Chat ID:
- Group Chat IDs are usually negative numbers
- Private chat IDs are usually positive numbers
- Double-check you're using the correct ID format
Topic ID not working:
- Make sure topics are enabled in your supergroup
- Verify you're getting the Topic ID from the correct topic
- Topic IDs are only needed for supergroups with topics
API returns empty:
- Send a fresh message to your bot/group
- Make sure your bot token is correct
- Check that the bot has received recent messages
📝 Notes
- Chat IDs remain constant, so you only need to find them once
- Topic IDs also remain constant unless the topic is deleted and recreated
- Keep your bot token secure and never share it publicly
- For production use, consider using environment variables instead of hardcoding IDs
🆘 Need Help?
If you're still having trouble:
- Check the bot logs for error messages
- Verify your bot token is valid
- Ensure the bot has proper permissions in your chat/group
- Try sending a test message manually to confirm the setup