Telegram Bot Token
Goal
Create a Telegram bot, obtain its bot token, verify the token with curl, and find the numeric IDs commonly needed when integrating the bot with another service.
The main values are:
- bot token: secret credential used to call the Telegram Bot API
- bot ID: numeric ID of the bot account
- user ID: numeric ID of a Telegram user who sends a message to the bot
- chat ID: numeric ID of a private chat, group, supergroup, or channel
A Telegram username such as @example is not the same as a numeric user ID.
Create a bot with BotFather
- Open Telegram.
- Message @BotFather.
- Send:
/newbot
- Choose a display name, such as
Example Bot. - Choose a username that ends with
bot, such asexample_helper_bot. - Copy the token returned by BotFather.
A token looks like this:
123456789:ABCdefGHIjklMNOpqrSTUvwxYZ
Treat the token like a password. Anyone with the token can control the bot through the Telegram Bot API.
If the token leaks, message BotFather and use /revoke to rotate it.
Verify the bot token
Call the getMe endpoint:
curl -s "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getMe" | jq
A successful response has ok: true:
{
"ok": true,
"result": {
"id": 123456789,
"is_bot": true,
"first_name": "Example Bot",
"username": "example_helper_bot"
}
}
The bot ID is result.id.
To print only the bot ID:
curl -s "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getMe" \
| jq '.result.id'
To print the bot ID and username together:
curl -s "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getMe" \
| jq '{id: .result.id, username: .result.username}'
Find a user ID
To find the numeric user ID for a Telegram account, send any message to the bot from that account. Then call getUpdates:
curl -s "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates" | jq
Look for message.from.id:
{
"ok": true,
"result": [
{
"update_id": 100000000,
"message": {
"from": {
"id": 987654321,
"is_bot": false,
"first_name": "Example",
"username": "example_user"
},
"chat": {
"id": 987654321,
"type": "private"
},
"text": "hello"
}
}
]
}
Use message.from.id as the user ID.
To print only user IDs from received messages:
curl -s "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates" \
| jq '.result[].message.from.id'
To inspect user ID, chat ID, username, and chat type together:
curl -s "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates" \
| jq '.result[] | {user_id: .message.from.id, chat_id: .message.chat.id, username: .message.from.username, chat_type: .message.chat.type}'
Find a chat ID
For a private chat, message.chat.id is usually the same as message.from.id.
For a group, supergroup, or channel, message.chat.id is different from the user ID. Group and supergroup IDs are often negative numbers.
To print chat IDs:
curl -s "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates" \
| jq '.result[].message.chat.id'
For group messages, inspect the chat title and type:
curl -s "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates" \
| jq '.result[] | {chat_id: .message.chat.id, title: .message.chat.title, type: .message.chat.type}'
Reset or clear pending updates
getUpdates returns pending updates that have not been acknowledged by the bot API client. After reading an update, pass an offset greater than the latest update_id to mark older updates as handled.
Example:
curl -s "https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates?offset=<LAST_UPDATE_ID_PLUS_ONE>" | jq
If another bot client is already polling with the same token, it may consume updates before your curl command sees them.
Group privacy mode
Telegram bots have privacy mode enabled by default. In groups, a bot with privacy mode enabled can usually see only:
- commands that start with
/ - replies to the bot
- service messages
If the bot must receive ordinary group messages, change privacy mode in BotFather:
- Message @BotFather.
- Send
/mybots. - Select the bot.
- Open Bot Settings → Group Privacy.
- Choose Turn off.
- Remove and re-add the bot to the group.
Telegram caches the privacy setting when the bot joins a group, so removing and re-adding the bot is required after changing the setting.