Skip to content

Instantly share code, notes, and snippets.

@nafiesl
Last active October 23, 2025 10:42
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 ↑

@heeeed86
Copy link

Hi, I'm new to github, and looking for help with my telegram bot.
I'm building a system to deliver timed messages.
I've built the backend and the features of the bot which all work and correspond with my sheets.
But I'm having difficulties with sending the texts.. /start runs and collects telegram id.
But I cannot get it to collect the chat id which is what I believe is failing?!
I can force send the messages to all users.
But that's only from inside the code. If I use a command like startover from telegram rather than the script, it wipes my sheet but does not send the first text.

So the webhook and api appear to be working..?
But I'm not sure if this is due to the privacy described a few comments ago. Or is somewhere else

Here is a snippet of the code I'm using during my onboarding phase of my script.

function doPost(e) {
try {
const contents = JSON.parse(e.postData.contents);
const message = contents.message;
if (!message || !message.chat || !message.from) return;

const userId = message.from.id;
const chatId = message.chat.id;
const text = message.text ? message.text.trim() : "";
const sheet = SpreadsheetApp.openById(SPREADSHEET_ID).getSheetByName("Users");
const userRow = findOrCreateUserRow(sheet, userId);

Any help and I would be most greatful

@bennyzhe
Copy link

Thanks a lot

@JeromeL63
Copy link

JeromeL63 commented Jul 28, 2025

Hello Someone found a solution, open Telegram on PC : (https://stackoverflow.com/a/69302407)
and the URL show you tchatID web.telegram.org/a/#-XXXXXXX

@tufanpalash4-create
Copy link

Help

@TylonHH
Copy link

TylonHH commented Aug 15, 2025

Help

Don’t spam here. If you wanna get help specify your issue. I have forgotten my fortune teller crystal ball 🔮 at home.

@mattmclartybiz
Copy link

When I do this for a private chat it says "might be temporarily down or it may have moved permanently to a new web address"

@Barnabas2
Copy link

It doesn't seem to work anymore.. I tried even with a bot that I got the ID in the past and now the url i.e. in this format https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/getUpdates does not take you anywhere. Anyone else has this problem?

@bozenc
Copy link

bozenc commented Sep 13, 2025

I have the same problem. I haven't been able to get a chat ID for two days. I've tried everything. I've tried everything, but there's a problem. What's the solution?

@Barnabas2
Copy link

Barnabas2 commented Sep 13, 2025

I have the same problem. I haven't been able to get a chat ID for two days. I've tried everything. I've tried everything, but there's a problem. What's the solution?

I noticed in the terminal, if you write curl https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/getUpdates it returns a response. But the normal web browser takes you nowhere.

@bozenc
Copy link

bozenc commented Sep 14, 2025

I have the same problem. I haven't been able to get a chat ID for two days. I've tried everything. I've tried everything, but there's a problem. What's the solution?

I noticed in the terminal, if you write curl https://api.telegram.org/bot63xxxxxx71:AAFoxxxxn0hwA-2TVSxxxNf4c/getUpdates it returns a response. But the normal web browser takes you nowhere.

With curl I was able to see my old bots ID's but the new ones I create return empty "result":[]

Hello,
The old bot suddenly stopped working.
I created a new bot, and I obtained the chat ID using different methods, but it is not responding on the api.telegram.org page. I am uncertain how to resolve this issue.

@vyagi
Copy link

vyagi commented Sep 16, 2025

I have (just at this very moment) discovered that this id is now in the url of the chat

@obulisaravanan
Copy link

In telegram search for @WhatChatIDBot click on start you wil get chat ID.

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