Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to obtain the chat_id of a private Telegram channel?

Tags:

telegram-bot

I found the way to write in private channels.

  1. You should convert it to public with some @channelName

  2. Send message to this channel through Bot API

    https://api.telegram.org/bot111:222/sendMessage?chat_id=@channelName&text=123

  3. As response you will get info with chat_id of your channel.

    {
      "ok" : true,
      "result" : {
        "chat" : {
          **"id" : -1001005582487,**
          "title" : "Test Private Channel",
          "type" : "channel"
        },
        "date" : 1448245538,
        "message_id" : 7,
        "text" : "123ds"
      }
    }
    
  4. Now you can convert Channel back to private (by deleting channel's link) and send message directly to this chat_id "-1001005582487"

    https://api.telegram.org/bot111:222/sendMessage?chat_id=-1001005582487&text=123


update #2 :

Found another one easiest way : Just send to @username_to_id_bot (https://t.me/username_to_id_bot) bot your invite link to your private channel, it will return it's ID. Simplest level : maximum! :)

ps. I am not an owner of this bot.

ps2. Bot will not join your group, but to be sure in security, just revoke your old invitation link if it is matter for you after bot using.

Original post :

Make channel public cannot be done by user with exist at least 5 public groups/channels, so...problem not solved. Yes, you can revoke one of them, but for now, we cannot retrieve chat id other way.

revoke

Did anybody found solution for that case?

update

I found crazy solution :

  1. login under your account at web version of Telegram : https://web.telegram.org
  2. Find your channel. See to your url, it should be like https://web.telegram.org/#/im?p=c**1055587116**_11052224402541910257
  3. Grab "1055587116" from it, and add "-100" as a prefix.

So... your channel id will be "-1001055587116". Magic happen :)

Solution found here : https://github.com/GabrielRF/telegram-id#web-channel-id


Open the private channel, then:

  • on web client:

    • look at the URL in your browser:
    • if it's for example https://web.telegram.org/#/im?p=c1192292378_2674311763110923980
    • then 1192292378 is the channel ID
  • on mobile and desktop:

    • copy the link of any message of the channel:
    • if it's for example https://t.me/c/1192292378/31
    • then 1192292378 is the channel ID (bonus: 31 is the message ID)
  • on Plus Messenger for Android:

    • open the infos of the channel:
    • the channel ID appears above, right under its name

WARNING be sure to add -100 prefix when using Telegram Bot API:

  • if the channel ID is for example 1192292378
  • then you should use -1001192292378

The easiest way is to invite @get_id_bot in your chat and then type:

/my_id @get_id_bot

Inside your chat


  • Open Telegram Web at https://web.telegram.org
  • search you private channel
  • Look at the URL. It's like: https://web.telegram.org/#/im?p=cXXXXXXXXXX_578236787445474833

The id of your private channel is the XXXXXX part (between the "p=c" and the underscore). To use it, just add "-100" in front of it. So if "XXXXXX" is "4785444554" your private channel id id "-1004785444554".


For now you can write an invite link to bot @username_to_id_bot and you will get the id:

example: enter image description here

also works with public chats, channels and even users


Actually, it is pretty simple.

All you need to do is to:

  1. Invite the bot to the channel/group (doesn't matter private or not).
  2. Send any message in the channel/group.
  3. Go to getUpdates API URL in the browser:
    https://api.telegram.org/bot<BOT_TOKEN>/getUpdates
    

Now, look at the results.
You will see a JSON output. In this JSON, look for the chat data. Usually, latest updates are at the end.

{
   "ok":true,
   "result":[
      ... 
      {
         ... 
         "my_chat_member":{
            "chat":{
               "id":-100987654321,
               "title":"My Channel",
               "type":"channel"
            },
            ...
         }
      }
   ]
}

Your chat ID is -100987654321.