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"
- open the channel
- 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"
- open the group
Here is the setup of admins of the channel:
At the end of the day, the setup of the chat/group is the following in the telegram UI:
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?
2
Answers
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 forchat_id
that you’re passing@TestChannelChat
doesn’t belong to your chat. You have to pass theid
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://stackoverflow.com/a/38388851/10359385used send post/message your private chat: