I'm using my bot to tell important news, but when I using 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?
This question is related to
telegram
telegram-bot
This is how I've added a bot to my channel and set up notifications:
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
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.
As of now:
To add the bot to your channel:
* 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.
Source: Stackoverflow.com