Telegram Bot Token Explained: Format, Security, and Best Practices
A Bot Token is a secret credential that grants full control of a Telegram bot. It is generated by @BotFather and used to authenticate API requests.
Token Format
A bot token looks like: 123456789:ABCdefGHIjklMNOpqrSTUvwxYZ
- The part before the colon (
123456789) is the bot's numeric User ID. - The part after the colon is a secret authentication hash.
Security Best Practices
- Never commit tokens to Git. Use environment variables or a secret manager.
- Never share tokens in public channels, Stack Overflow, or GitHub issues.
- Use environment variables: Store the token in
.envfiles that are in your.gitignore. - Rotate tokens periodically: Use
/revokein @BotFather to generate a new token. - Monitor for abuse: If your bot starts behaving unexpectedly, your token may be compromised.
What Can Someone Do With Your Token?
Anyone with your bot token can: send messages as your bot, read incoming messages, access files sent to the bot, change the bot's profile, and set webhooks. They effectively have full control of the bot.
If Your Token Is Compromised
- Go to @BotFather immediately.
- Send
/revokeand select the compromised bot. - A new token is generated. The old token stops working instantly.
- Update your application with the new token.
- Check
getWebhookInfoto ensure no unauthorized webhook was set.
Frequently Asked Questions
Can I have multiple tokens for the same bot?
No. Each bot has exactly one active token at a time. When you revoke a token, the old one is immediately invalidated and a new one is generated. You cannot have two valid tokens simultaneously.
Is it safe to expose the Bot ID (the number before the colon)?
Yes. The Bot ID is the same as the bot's public User ID, which anyone can look up by username. Only the hash after the colon is secret. However, revealing the full token format (including the ID) in logs or error messages should be avoided.