Skip to content

Instantly share code, notes, and snippets.

@nafiesl
Last active February 27, 2025 10:31
Show Gist options
  • Save nafiesl/4ad622f344cd1dc3bb1ecbe468ff9f8a to your computer and use it in GitHub Desktop.
Save nafiesl/4ad622f344cd1dc3bb1ecbe468ff9f8a to your computer and use it in GitHub Desktop.
How to get Telegram Bot Chat ID

How to get Telegram Bot Chat ID

Content :

  1. Create a Telegram Bot and get a Bot Token
  2. Get Chat ID for a Private Chat
  3. Get Chat ID for a Channel
  4. Get Chat ID for a Group Chat
  5. Get Chat ID for a Topic in a Group Chat

Create a Telegram Bot and get a Bot Token

  1. Open Telegram application then search for @BotFather
  2. Click Start
  3. Click Menu -> /newbot or type /newbot and hit Send
  4. Follow the instruction until we get message like so
    Done! Congratulations on your new bot. You will find it at t.me/new_bot.
    You can now add a description.....
    
    Use this token to access the HTTP API:
    63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c
    Keep your token secure and store it safely, it can be used by anyone to control your bot.
    
    For a description of the Bot API, see this page: https://core.telegram.org/bots/api
    
  5. So here is our bot token 63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c (make sure we don't share it to anyone).

Back to top ↑

Get Chat ID for a Private Chat

  1. Search and open our new Telegram bot
  2. Click Start or send a message
  3. 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
  4. We will see a json like so
    {
      "ok": true,
      "result": [
        {
          "update_id": 83xxxxx35,
          "message": {
            "message_id": 2643,
            "from": {...},
            "chat": {
              "id": 21xxxxx38,
              "first_name": "...",
              "last_name": "...",
              "username": "@username",
              "type": "private"
            },
            "date": 1703062972,
            "text": "/start"
          }
        }
      ]
    }
    
  5. Check the value of result.0.message.chat.id, and here is our Chat ID: 21xxxxx38
  6. Let's try to send a message: https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=21xxxxx38&text=test123
  7. When we set the bot token and chat id correctly, the message test123 should be arrived on our Telegram bot chat.

Back to top ↑

Get Chat ID for a Channel

  1. Add our Telegram bot into a channel
  2. Send a message to the channel
  3. Open this URL https://api.telegram.org/bot{our_bot_token}/getUpdates
  4. We will see a json like so
    {
      "ok": true,
      "result": [
        {
          "update_id": 838xxxx36,
          "channel_post": {...},
            "chat": {
              "id": -1001xxxxxx062,
              "title": "....",
              "type": "channel"
            },
            "date": 1703065989,
            "text": "test"
          }
        }
      ]
    }
    
  5. Check the value of result.0.channel_post.chat.id, and here is our Chat ID: -1001xxxxxx062
  6. Let's try to send a message: https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=-1001xxxxxx062&text=test123
  7. When we set the bot token and chat id correctly, the message test123 should be arrived on our Telegram channel.

Back to top ↑

Get Chat ID for a Group Chat

The easiest way to get a group chat ID is through a Telegram desktop application.

  1. Open Telegram in a desktop app
  2. Add our Telegram bot into a chat group
  3. Send a message to the chat group
  4. 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
  5. To use the group chat ID in the API, we need to prefix it with the number -100, like so: -100194xxxx987
  6. Now let's try to send a message: https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/sendMessage?chat_id=-100194xxxx987&text=test123
  7. When we set the bot token and chat id correctly, the message test123 should be arrived on our group chat.

Back to top ↑

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.

  1. 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 is 11.
  2. 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
  3. When we set the bot token and chat id correctly, the message test123 should be arrived inside our group chat topic.

Back to top ↑

@nafiesl
Copy link
Author

nafiesl commented Sep 7, 2024

Can't I get a chat ID for private conversations from a bot that doesn't belong to me?

@skdplay, Same logic with the "Get Chat ID for a Private Chat", as long as someone else start conversation or send message to your bot, you will see their chat_id from the https://api.telegram.org/bot{our_bot_token}/getUpdates endpoint.

@ilium007
Copy link

ilium007 commented Sep 7, 2024

I ended up adding @MissRose_bot to the chat and issuing /id

@skdplay
Copy link

skdplay commented Sep 8, 2024

@nafiesl No bot tokens because it's not my bot

@ilium007
Copy link

ilium007 commented Sep 8, 2024

@skdplay - then create a bot, get the token, and add it to the chat

@skdplay
Copy link

skdplay commented Sep 8, 2024

@ilium007 No, you're not using my bot, it means you're using private chat and want the chat ID of another bot.

@nafiesl
Copy link
Author

nafiesl commented Sep 9, 2024

Can't I get a chat ID for private conversations from a bot that doesn't belong to me?

Ah I see, I was misunderstood your question. When you don't have the bot token, then you can't get the chat ID.

@lydnguyen
Copy link

I tried the URL link method and included my bot token as well. But I keep getting this result back {"ok":true,"result":[]}. Does anyone know why and how I can retrieve the chatID?

@nafiesl
Copy link
Author

nafiesl commented Sep 13, 2024

I tried the URL link method and included my bot token as well. But I keep getting this result back {"ok":true,"result":[]}. Does anyone know why and how I can retrieve the chatID?

@lydnguyen I think you need to send message first. Ff it doesn't work, try to end conversation and start again. Sometimes I experience the same issue, too.

@yash760
Copy link

yash760 commented Sep 13, 2024

Thanks a lot!!!!

@horia-delicoti
Copy link

Helpful! Thank you, sir!

@dongphuchaitrieu
Copy link

Great tutorial! Thank you!

@dripboidrip
Copy link

hello, I tried to get the bot chat I’d using your instructions but when I put opened the url on browser it only says {“ok” : true, “result”:[ ] } it doesn’t show anything else. Does it mean my bot isn’t functioning properly?

@nafiesl
Copy link
Author

nafiesl commented Nov 23, 2024

hello, I tried to get the bot chat I’d using your instructions but when I put opened the url on browser it only says {“ok” : true, “result”:[ ] } it doesn’t show anything else. Does it mean my bot isn’t functioning properly?

No, sometimes I get the same result too. The solution, you need restart the conversation with the bot (end conversation then start again), then try to visit the getUpdate URL again in the browser. Ensure you were using the correct bot token.

@dripboidrip
Copy link

thanks man, it worked!

@batache02
Copy link

thanks bro

@azizbeksiddikov
Copy link

Thanks, very helpful!

@Abir-Tx
Copy link

Abir-Tx commented Dec 6, 2024

Nice and organized. Thanks

@nafiesl
Copy link
Author

nafiesl commented Dec 18, 2024

How to "end a conversation"

screen_2024-12-18_006

@ElMaquinistaDeTodo, try these steps to restart a conversation with a telegram bot:

  1. Click the option button (3 dots)
  2. Click Delete chat, a confirmation dialog will pop up.
  3. Check the Stop and block bot
  4. Click Delete.
  5. Then search the bot again, click Start (or Restart) to start conversation again
  6. Next, follow the steps above (Get Chat ID for a Private Chat) from number 1

@Shyzer
Copy link

Shyzer commented Dec 18, 2024

The latest Telegram desktop app for Windows (5.9) doesn't have the "Right click on the message and click Copy Message Link" option. I'm only able to "Copy Text," as seen here

@nafiesl
Copy link
Author

nafiesl commented Dec 29, 2024

The latest Telegram desktop app for Windows (5.9) doesn't have the "Right click on the message and click Copy Message Link" option. I'm only able to "Copy Text," as seen here

Hi @Shyzer, do you still have this issue?
Please have a look at this comment.

@fame01
Copy link

fame01 commented Jan 9, 2025

Question being a noob learner, would an automatic bot be considered as "Private" or group or channel"?

I got this when I applied Private

ok | true -- | -- result | []

@nafiesl
Copy link
Author

nafiesl commented Jan 9, 2025

Question being a noob learner, would an automatic bot be considered as "Private" or group or channel"?

I got this when I applied Private
ok | true -- | -- result | []

It depends on where you put the bot. When you chat with the bot privately, then it will be a private chat. When you add the chat in a group, then it will be a group. Same goes for channel.

When you only get the result above, you need to send a message to the bot (on privact chat, group, or channel). If you still get nothing, try to end chat with the bot, then start again. (Scroll comments above if you not sure how to do it).

@comman-fukui
Copy link

When I right-click on a group message and select “Copy Message Link”, I only get a URL of the form “https://t.me/(group name)/2”.
Has the format changed?

@Borevlad
Copy link

@Ahsan-Aziz-Ishan
Copy link

This does not work anymore

@pong106
Copy link

pong106 commented Jan 31, 2025

@TylonHH
Copy link

TylonHH commented Feb 1, 2025

When you only get the result above, you need to send a message to the bot (on privact chat, group, or channel). If you still get nothing, try to end chat with the bot, then start again. (Scroll comments above if you not sure how to do it).

I tried ending and starting a new chat with my bot, no luck
I invited the bot into a group, then I see results, but I prever a private chat. But no solution works (any more)

Workaround with a 3rd bot @RawDataBot forward a message to it...

@GameBully2K
Copy link

someone made a website named gettelegramchatid.com just for this😂

@ParajBhatt
Copy link

this is not working anymore anyone have solution ?

@nafiesl
Copy link
Author

nafiesl commented Feb 12, 2025

this is not working anymore anyone have solution ?

@ParajBhatt @Ahsan-Aziz-Ishan can you guys please explain more, which one does not work? Which steps and screenshot will be helpful.

I am just checking those 4 sections and here are the results:

  1. Get Chat ID for a Private Chat
    (still works with no change)
  2. Get Chat ID for a Channel
    (still works with 1 change, we don't need to send any message to the channel to get the channel chat ID)
  3. Get Chat ID for a Group Chat
    (this still works for public group, but not for private group. I will update the post with new section for private group chat)
  4. Get Chat ID for a Topic in a Group Chat
    (this still works no change)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment