In my own library I’m trying to send a message using “sendMessage” API method from Telegram Bot API. I’ve create a channel titled, say, “my_channel123” and my user name is “my_username123”. So I’m an admin of the channel and the only user.
When I’m trying to send a message to the whole channel or myself from a bot, I get an error Bad request 400
. Here’s how I’m trying to do that:
my_bot.send_message(chat_id="@my_channel123", text="tetfdsfd")
# or
my_bot.send_message(chat_id="@my_channel123my_username123", text= "tetfdsfd")
# or
my_bot.send_message(chat_id="@my_username123", text="tetfdsfd")
I believe the error is somewhere in the format of the ids of the channel or user name or both. Are all these 3 calls correct, meaning is the format I use for chat_id correct?
Note that most likely the probable case is the id of the chat or user_name (or rather, the format) or something else because other post and get methods in my library work properly.
2
Answers
You have to add the bot to be an administrator of the channel before it can send messages to the channel. After you do that, your first line should work:
Also remember that whatever follows the
@
should be the channel username, not the title.when sending a message to a channel, i think its easiest to send it with the channel id…
there are a few ways to get the channel id
@ChannelIdBot
… though the bot will still need to be in the channel as an admin, in order to send messages…