97

I'm using my bot to tell important news, but when I use sendMessage to the channel I'm receiving the following error:

{"ok":false,"error_code":403,"description":"Error: Forbidden: bot is not a participant of the channel"}

In the Change Log they mention it's not possible via the client to send a message to a channel, but then what is the other way to do that?

So, the question is, how to add my bot to the channel?

2

4 Answers 4

153

Now all clients allow to do it, but it's not pretty simple.
In any Telegram client:

  1. Open Channel info (in app title)
  2. Choose Administrators
  3. Add Administrator
  4. There will be no bots in contact list, so you need to search for it. Enter your bot's username
  5. Clicking on it you make it as administrator.

enter image description here

3
  • I have done the same thing ( I have added my bot as an administrator to my channel) still I am getting "bot is not a participant of the channel" error. Apr 8, 2016 at 9:29
  • 3
    For channels without an username, just give it one, send a message with a bot, the result of sendMessage should include a chat_id that can be used after you remove the channel name. Apr 14, 2016 at 22:38
  • Not working in any of the Web clients. I tried Z, K and legacy=1, but none of those Web clients have an Add Admin button under Administrators. If I check the mobile and desktop client, the I can indeed find the Add Addmin button. Please check and update your answer accordingly so people are not needlessly going through 3 different web clients like. Nov 21, 2021 at 9:41
70

This is how I've added a bot to my channel and set up notifications:

  1. Make sure the channel is public (you can set it private later)
  2. Add administrators > Type the bot username and make it administrator
  3. Your bot will join your channel
  4. set a channel id by setting the channel url like

telegram.me/whateverIWantAndAvailable

the channel id will be @whateverIWantAndAvailable

Now set up your bot to send notifications by pusshing the messages here:

https://api.telegram.org/botTOKENOFTHEBOT/sendMessage?chat_id=@whateverIWantAndAvailable&text=Test

the message which bot will notify is: Test

I strongly suggest an urlencode of the message like

https://api.telegram.org/botTOKENOFTHEBOT/sendMessage?chat_id=@whateverIWantAndAvailable&text=Testing%20if%20this%20works

in php you can use urlencode("Test if this works"); in js you can encodeURIComponent("Test if this works");

I hope it helps

5
  • How do i set it to private?
    – CodeGuru
    Jul 5, 2016 at 13:47
  • @CodeGuru - you can set this channel to be private in your telegram desctop or mobile client, if you was the channel administrator. For me this worked in this way - i firstly made channel public, send message by bot into this channel, than i made channel private, and bot could still send message in it. So, i assume, it works somehow. But after some etime it stopped working. So, i assume bots cannot send messages to private channels
    – vodolaz095
    May 27, 2017 at 21:51
  • there is some crazy solution mentioned here - stackoverflow.com/a/39943226/1885921
    – vodolaz095
    May 27, 2017 at 22:01
  • Also should be mentioned that the Add Admin button is only there in the mobile and desktop clients. It is not there in the Web clients currently, tried the webK alpha 0.9.1 and webZ alpha 1.22.3 versions. Nov 21, 2021 at 9:45
  • Best step by step for this issue as we can't no longer send messages to our own bot so we need to add him to a channel, thank you!! Jan 10 at 11:46
33

As of now:

  • Only the creator of the channel can add a bot.
  • Other administrators can't add bots to channels.
  • Channel can be public or private (doesn't matter)
  • bots can be added only as admins, not members.*

To add the bot to your channel:

  • click on the channel name: enter image description here

  • click on admins: enter image description here

  • click on Add Admin: enter image description here

  • search for your bot like @your_bot_name, and click add:** enter image description here

* In some platforms like mac native telegram client it may look like that you can add bot as a member, but at the end it won't work.
** the bot doesn't need to be in your contact list.

5
  • From Desktop (linux), it tells me "This user is not a subscriber of this channel. Add them to channel and promote to admin?" I say yes, and nothing happens (no error message, but doesn't add it). From mobile, I do get an error message, saying "you can't add this user as an admin because they are not a member and you are not allowed to add them", which is nonsense. Anyone? (the channel has already more than 200 subscribers, so I can't add users anyway, but this shouldn't prevent me from adding a bot)
    – matteo
    Jan 28, 2019 at 19:58
  • @matteo are you the creator of the channel?
    – apadana
    Jan 28, 2019 at 23:05
  • @matteo I have the same problem. Did you find any resolution for this?
    – MortezaE
    May 14, 2019 at 21:37
  • 1
    @MortezaE turned out the creator of the channel hadn't given me all the needed permissions. I can't remember the details now, however the error messages weren't informative enough, and completely non-existent on Desktop, both of which are Telegram's fault. Once I had all the needed permissions it fixed the problem.
    – matteo
    May 16, 2019 at 14:43
  • 1
    Here are the details: I had the permissions to add admins but not the one to add members. On mobile, when trying to add the bot as member it gave me the wrong error message telling me I couldn't because there were already 200 members (obvious nonsense, that shouldn't apply to bots) when in fact the reason was I didn't have the permission in the first place. And as I said, no error message whatsoever on desktop
    – matteo
    May 16, 2019 at 14:46
7

Are you using the right chat_id and including your bot's token after "bot" in the address? (api.telegram.org/bottoken/sendMessage)

This page explains a few things about sending (down in "sendMessage" section) - basic stuff, but I often forget the basics.

To quote:

In order to use the sendMessage method we need to use the proper chat_id.

First things first let's send the /start command to our bot via a Telegram client.

After sent this command let's perform a getUpdates commands.

curl -s \
-X POST \ https://api.telegram.org/bot<token>/getUpdates \ | jq .

The response will be like the following

{   "result": [
     {
       "message": {
        "text": "/start",
         "date": 1435176541,
         "chat": {
           "username": "yourusername",
           "first_name": "yourfirstname",
           "id": 65535
         },
         "from": {
           "username": "yourusername",
           "first_name": "yourfirstname",
           "id": 65535
         },
         "message_id": 1
       },
       "update_id": 714636917
     }    ],   "ok": true }

We are interested in the property result.message[0].chat.id, save this information elsewhere.

Please note that this is only an example, you may want to set up some automatism to handle those informations Now how we can send a message ? It's simple let's check out this snippet.

curl -s \
-X POST \ https://api.telegram.org/bot<token>/sendMessage \
-d text="A message from your bot" \
-d chat_id=65535 \ | jq .

Where chat_id is the piece of information saved before.

I hope that helps.

4
  • I may wrongly post the question.. You need to understand my req... I have working code which can sendMessage to user no issues .. I'm talking about sending message to Channels .... Please
    – user4374121
    Oct 14, 2015 at 15:26
  • I'm sorry - I did not pay attention to that. It looks like what you are trying to do is not yet implemented (according to the changelog you have already looked at): "You can now 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). For this to work, the bot must be an administrator in the channel (and that‘s exactly what Telegram clients don’t support yet — adding bots as administrators coming soon)."
    – JGR
    Oct 14, 2015 at 15:59
  • @Rosini confirmed with bot support - you can't add a bot to admin in a channel, yet, and that's the only way a bot can post to a channel.
    – JGR
    Oct 14, 2015 at 19:30
  • Will this chat_id remain constant? Do I have to do getUpdates periodically or for every message?
    – balki
    May 13, 2017 at 4:57