How to obtain the chat_id of a private Telegram channel?

你离开我真会死。 提交于 2019-12-17 15:09:06

问题


I use curl to update my public channels. This kind of syntax:

>curl -X POST "https://api.telegram.org/bot144377327:AAGqdElkZ-77zsPRoAXXXXXXXXXX/sendMessage" -d "chat_id=@MyChannel&text=my sample text"

But what's the chat_id of a private channel? It's not the one you have in the private invite.

Because now we can pass a channel username (in the format @channelusername) in the place of chat_id in all methods (and instead of from_chat_id in forwardMessage). But what's the @channelusername of a private channel that I administer?


回答1:


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




回答2:


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.

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=c1055587116_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




回答3:


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

/my_id@get_id_bot

Inside your chat




回答4:


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



回答5:


You Can Too Do This:

Step 1)Convert Your Private Channel To Public Channel

Step 2)Set The ChannelName For This Channel

Step 3)then you Can change this Channel to Private

Step 4)Now Sending Your Message Using @ChannelName That you Set In Step 3

note:For Step 1 You Can Change One of Your Public Channel To Private For a short time.




回答6:


No need to convert the channel to public then make it private.

  1. find the id of your private channel. (There are numerous methods to do this, for example see this SO answer)

  2. curl -X POST "https://api.telegram.org/botxxxxxx:yyyyyyyyyyy/sendMessage" -d "chat_id=-100CHAT_ID&text=my sample text"

    replace xxxxxx:yyyyyyyyyyy with your bot id, and replace CHAT_ID with the channel id found in step 1. So if channel id is 1234 it would be chat_id=-1001234.

All done!




回答7:


  • 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".




回答8:


NEEDED ANSWER:

You should add & make your BOT as administrator of the PRIVATE channel, otherwise chat not found error happens.




回答9:


The option that I do is by using the popular Plus Messenger on Android. The play store link is: https://play.google.com/store/apps/details?id=org.telegram.plus&hl=en

You can click on the Channel and in Channel info below the group name, you can find Channel Id.

Supergroup and Channel Ids will looks like 1068773197 on plus messenger. For your usage on API, you can prefix -100 which would make it -1001068773197.



来源:https://stackoverflow.com/questions/33858927/how-to-obtain-the-chat-id-of-a-private-telegram-channel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!