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:
XXXXXXX_bot
with Botfather by getting the token: no problemTestChannel
XXXXXXX_bot
TestChannel
TestChannelChat
TestChannelChat
XXXXXXX_bot
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?
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://stackoverflow.com/a/38388851/10359385