Send a message on telegram: "Forbidden: bot is not a member of the supergroup chat" or "Forbidden: bot is not a member of the channel chat"
Asked Answered
O

3

7

I am trying to send a message on a chat on telegram. I want telegram setups to be done only with the official UI as I want it to be possibly done by by an end user.

Here are telegram setup I do:

  • I created the bot XXXXXXX_bot with Botfather by getting the token: no problem
  • I created a Channel:
    • click "new channel"
    • channel name: TestChannel
    • click "Next"
    • select "Private channel"
    • click "Save"
    • Add my bot XXXXXXX_bot
    • Click "Make admin"
    • Click "Save"
  • I create the chat:
    • open the channel TestChannel
    • on the channel menu, select "Manage Channel"
    • click on "Add a group" in the discussion
    • click on "Create a new group"
    • group name: TestChannelChat
    • click "Create"
    • click "Save"
  • I add the bot to the new group:
    • open the group TestChannelChat
    • on the right panel, I click "add member"
    • Add my bot XXXXXXX_bot
    • click "Add"
    • right click on the newly added user in the chat and select "Promote to admin"
    • click "Save"

Here is the setup of admins of the channel:

enter image description here

At the end of the day, the setup of the chat/group is the following in the telegram UI:

enter image description here

I make the following http call :

GET https://api.telegram.org/botXXXXXXTOKENXXXXXXX/sendMessage?chat_id=@TestChannelChat&text=coucou

that gives me the following answer:

{
  "ok": false,
  "error_code": 403,
  "description": "Forbidden: bot is not a member of the supergroup chat"
}

I also made the following (to bypass the actual chat and directly publish a message in the channel):

GET https://api.telegram.org/botXXXXXXTOKENXXXXXXX/sendMessage?chat_id=@TestChannel&text=coucou

that gives me the following answer:

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

One simple question, as a bot is also meant to broadcast messages, what part of its setup am I missing?

Occam answered 16/1, 2021 at 18:3 Comment(0)
V
7

You are in a right track for working with Telegram bots. But first understand about chat_id.

chat_id is either chat username or id of the chat. You can set username only for Public chats/groups. In your case you have a private group and there's no username for it. The value for chat_id that you're passing @TestChannelChat doesn't belong to your chat. You have to pass the id of the chat or set a public username and pass it.

If you don't know how to check id of the chat, read here: https://mcmap.net/q/80446/-telegram-bot-how-to-get-a-group-chat-id

Viridian answered 17/1, 2021 at 6:31 Comment(3)
Cool, thanks. Is there a neater way to get the id of the chat?Occam
You can get from bot updates API too. api.telegram.org/bot{token}/getUpdatesViridian
This is what I did, but sending a dummy message to the chat, and then, polling received message by the bot is not very "neat". I expected something like api.telegram.org/MyUserTokenThatIGetIDontKnowHow/getChannelsOccam
C
0

used send post/message your private chat:

@dispatcher.message_handler(chat_type=[ChatType.SUPERGROUP])
async def send_chat_msg(message: types.Message):
    await bot.send_message(f'Message in your private chat ', reply_markup=markup)
Colorcast answered 12/6, 2022 at 7:0 Comment(0)
R
0

this should be easy as follows to get rid of this error

"Forbidden: bot is not a member of the supergroup chat" or "Forbidden: bot is not a member of the channel chat"
  • click the name of the channel at the top and click edit icon
  • click administrators
  • add your tg_bot as administrator and thats all

administration screen short in telegram

Rogers answered 12/7 at 3:40 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.