How to get Telegram Bot Chat ID?
Create a Telegram Bot and get a Bot Token
Open Telegram application then search for
@BotFather
Click Start
Click Menu -> /newbot or type
/newbot
and hit SendFollow the instruction until we get message like so
So here is our bot token
63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c
(make sure we don't share it to anyone).
Get Chat ID for a Private Chat
Search and open our new Telegram bot
Click Start or send a message
Open this URL in a browser
https://api.telegram.org/bot{our_bot_token}/getUpdates
See we need to prefix our token with a word
bot
Eg:
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/getUpdates
We will see a json like so
Check the value of
result.0.message.chat.id
, and here is our Chat ID:21xxxxx38
Let's try to send a message:
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=21xxxxx38&text=test123
When we set the bot token and chat id correctly, the message
test123
should be arrived on our Telegram bot chat.
Get Chat ID for a Channel
Add our Telegram bot into a channel
Send a message to the channel
Open this URL
https://api.telegram.org/bot{our_bot_token}/getUpdates
We will see a json like so
Check the value of
result.0.channel_post.chat.id
, and here is our Chat ID:-1001xxxxxx062
Let's try to send a message:
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=-1001xxxxxx062&text=test123
When we set the bot token and chat id correctly, the message
test123
should be arrived on our Telegram channel.
Get Chat ID for a Group Chat
The easiest way to get a group chat ID is through a Telegram desktop application.
Open Telegram in a desktop app
Add our Telegram bot into a chat group
Send a message to the chat group
Right click on the message and click
Copy Message Link
We will get a link like so:
https://t.me/c/194xxxx987/11/13
The pattern:
https://t.me/c/{group_chat_id}/{group_topic_id}/{message_id}
So here is our Chat ID:
194xxxx987
To use the group chat ID in the API, we need to prefix it with the number
-100
, like so:-100194xxxx987
Now let's try to send a message:
https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=-100194xxxx987&text=test123
When we set the bot token and chat id correctly, the message
test123
should be arrived on our group chat.
Get Chat ID for a Topic in a Group Chat
In order to send a message to a specific topic on Telegram group, we need to get the topic ID.
Similar to steps above, after we click the
Copy Message Link
, we will get a link like:https://t.me/c/194xxxx987/11/13
, so the group Topic ID is11
.Now we can use it like so (see
message_thread_id
):https://api.telegram.org/bot783114779:AAEuRWDTFD2UQ7agBtFSuhJf2-NmvHN3OPc/sendMessage?chat_id=-100194xxxx987&message_thread_id=11&text=test123
When we set the bot token and chat id correctly, the message
test123
should be arrived inside our group chat topic.
Last updated