123 lines
3.7 KiB
Markdown
123 lines
3.7 KiB
Markdown
# 📱 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:
|
|
1. Open Telegram and search for `@BotFather`
|
|
2. Start a chat with BotFather
|
|
3. Send `/newbot` command
|
|
4. Follow the instructions to create your bot
|
|
5. Save the **Bot Token** (you'll need this for your `.env` file)
|
|
|
|
### 2. Get Your Chat ID
|
|
|
|
#### Method 1: Using @userinfobot (Easiest)
|
|
1. Search for `@userinfobot` in Telegram
|
|
2. Start a chat and send any message
|
|
3. The bot will reply with your **Chat ID**
|
|
|
|
#### Method 2: Using Telegram Web API
|
|
1. Send a message to your bot
|
|
2. Open this URL in your browser (replace `YOUR_BOT_TOKEN` with your actual bot token):
|
|
```
|
|
https://api.telegram.org/botYOUR_BOT_TOKEN/getUpdates
|
|
```
|
|
3. Look for the `"chat":{"id":` field in the response
|
|
4. The number after `"id":` is your **Chat ID**
|
|
|
|
#### Method 3: For Group Chats
|
|
1. Add your bot to the group
|
|
2. Send a message in the group
|
|
3. Use the same API URL as Method 2
|
|
4. Look for the chat object with `"type":"group"` or `"type":"supergroup"`
|
|
5. 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:
|
|
|
|
1. Create or open the topic where you want notifications
|
|
2. Send a message in that specific topic
|
|
3. Use the API URL from Method 2 above
|
|
4. Look for `"message_thread_id"` in the response
|
|
5. This number is your **Topic ID**
|
|
|
|
#### Alternative Method for Topic ID:
|
|
1. Right-click on a message in the topic
|
|
2. Select "Copy Message Link"
|
|
3. The URL will look like: `https://t.me/c/XXXXXXXXX/YYYY/ZZZZ`
|
|
4. The `YYYY` number is your **Topic ID**
|
|
|
|
## 🔧 Configuration
|
|
|
|
Once you have your IDs, add them to your `.env` file:
|
|
|
|
```env
|
|
# 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:
|
|
|
|
```bash
|
|
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:
|
|
1. Check the bot logs for error messages
|
|
2. Verify your bot token is valid
|
|
3. Ensure the bot has proper permissions in your chat/group
|
|
4. Try sending a test message manually to confirm the setup |