可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I use curl to update a 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?
Thank you
回答1:
I found the way to write in private channels.
- You should convert it to public with some @channelName
Send message to this channel through Bot API
https://api.telegram.org/bot111:222/sendMessage?chat_id=@channelName&text=123
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" } }
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 :
- login under your account at web version of Telegram : https://web.telegram.org
- Find your channel. See to your url, it should be like https://web.telegram.org/#/im?p=c1055587116_11052224402541910257
- 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:
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.
回答5:
No need to convert the channel to public then make it private.
find the id of your private channel. (There are numerous methods to do this, for example see this SO answer)
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!