Publish message to telegram Public Channel

Dear All;
I have developoed an analysis tool using Google Apps Script which utilizes Javascript. I need to publish the output to a public telegram channel. I did followings:

  1. I prepared a public channel.

  2. I created a bot using botFather.

  3. I made the bot as the administrator of public channel.

  4. then I made the following HTTP GET request without success:

    var myUrl = ‘https://api.telegram.org/bot[MY_BOT_TOKEN]/sendmessage?chat_id =MY_CHANNEL_NAME&text=’ + myMessage;
    ** UrlFetchApp.fetch(myUrl);**

The fetch command returns this error:

Exception: Invalid argument: https://api.telegram.org/bot(1246662861:AAFGejYXvmstfH-

Please somebody help me to solve this problem.

I thank you very much for soonest response.

Best Regards
Javad

You have to append your token directly to “https://api.telegram.org/bot” I can see an opening bracket “(” in the error message url.

If your bot token is “Je3nf5Il6rHfDN340” then the URL will be:
https://api.telegram.org/bot
Je3nf5Il6rHfDN340/sendmessage?chat_id= MY_CHANNEL_NAME&text= myMessage

first: remove the bracket “(”
https://api.telegram.org/bot(1246662861:AAFGejYXvmstfH-
2nd: place this token in the ‘telegram_bot_id’ variable in the conf.py file correctly.
By correctly i mean it should be placed as
telegram_bot_id=“bothttps://api.telegram.org/bot(1246662861:AAFGejYXvmstfH-”
(important is u should place ‘bot’ word before https.
Like this reply if you got it solved

thank you very much.
it was realy good.

Hello i’m trying to send message to my channel directly in my browser using this URL https://api.telegram.org/botMYTOKETBOT?chat_id=MYCHANNEL_NAME&text=myMESSAGE

I created a bot with botfather and i obtein the token(MYTOKETBOT), with that i achieved send message to my bot from google script, but i can’t send message to my telegram channel.

So i have a question:

  1. The bot token you use is the same token for the channel ?
  2. The channel have an ID or can i use the name of channel directly?

I solved my problem, setting my channel like public not private, thanks :grinning::grinning:

1 Like