How to use a Telegram Bot with a private channel (or how to post a message to a private channel)
TL;DR: just prepend -100 to the private channel ID and add your Telegram Bot as Admin to your channel.
UPDATE 2024-11-16
It seems there was a change in the Telegram API. If the instructions on this article don't work, try just prepending a -
instead of -100
. That did the trick for me. I haven't researched further, but the previous method (prepending -100
) still work in some services like activepieces (check that method)
Try both ways if the first one does not work.
You can also get the correct id using curl
# Replace YOUR_BOT_TOKEN with your actual bot token curl https://api.telegram.org/bot<YOUR_BOT_TOKEN>/getUpdates
and you will get something like this as a response:
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 920 100 920 0 0 7931 0 --:--:-- --:--:-- --:--:-- 7931 { "ok": true, "result": [ { "update_id": 1111111, "my_chat_member": { "chat": { "id": -11111111, # <- this is your ID "title": "title", "type": "group", "all_members_are_administrators": true }, "from": { "id": 11111111, "is_bot": false, "first_name": "Diego", "last_name": "Carrasco Gubernatis", "username": "diegocarrasco", "language_code": "en" }, "date": 111111111, "old_chat_member": { "user": { "id": 11111111, "is_bot": true, "first_name": "first_name", "username": "username" }, "status": "left" }, "new_chat_member": { "user": { "id": 111111111, "is_bot": true, "first_name": "first_name", "username": "username" }, "status": "member" } } }, { "update_id": 111111111, "message": { "message_id": 3, "from": { "id": 1111111111, "is_bot": false, "first_name": "Diego", "last_name": "Carrasco", "username": "username", "language_code": "en" }, "chat": { "id": -111111111, "title": "title", "type": "group", "all_members_are_administrators": true }, "date": 1731779802, "group_chat_created": true } } ] }
you can also test if your chat id is correct by using the following command (replace -123456789
with your chat id.)
curl -X POST \ https://api.telegram.org/bot<YOUR_BOT_TOKEN>/sendMessage \ -H 'Content-Type: application/json' \ -d '{"chat_id": "-123456789", "text": "Test message from curl"}'
END UPDATE