Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Telegram API with Google Apps Script

I'm searching an example of Telegram API usage with Google Apps Script, or anyone/anything that can help me to learn how to use this API, for instance to send a message to a certain user

like image 340
marcomow Avatar asked Feb 23 '14 11:02

marcomow


People also ask

Is there an API for Telegram?

We offer two kinds of APIs for developers. The Bot API allows you to easily create programs that use Telegram messages for an interface. The Telegram API and TDLib allow you to build your own customized Telegram clients.

How can I connect Telegram API?

Log in to your Telegram core: https://my.telegram.org. Go to "API development tools" and fill out the form. You will get basic addresses as well as the api_id and api_hash parameters required for user authorization. For the moment each number can only have one api_id connected to it.


2 Answers

I actively monitor Google Apps Script examples and I am not aware of samples integrating to the Telegram API. Given the level of security encryption required with the Telegram API I would suggest an integration with this service is unlikely due to Apps Script runtime limits.

I haven't found any examples to date of sending messages to a user but the Telegram service has posted large amounts of code, including their web client code, on Github and this would seem to be the best starting point for now.

Update: Telegram have created a Bot API which allows third party scripts to run in Telegram. The advantage of the Bot API is you don't need to do any message encryption. The PHP code sample could easily be ported to Apps Script.

like image 121
mhawksey Avatar answered Oct 07 '22 23:10

mhawksey


I was searching for something similar, and couldn't find any, so I have made my own, I will write it down here perhaps someone would make use of it.

This is a simple proof of concept that works:

function sendTelegramNotification(botSecret, chatId, body) {
var response = UrlFetchApp.fetch("https://api.telegram.org/bot" + botSecret + "/sendMessage?text=" + encodeURIComponent(body) + "&chat_id=" + chatId + "&parse_mode=HTML");
}

Other commands can be made same way.

like image 30
Mohammed R. El-Khoudary Avatar answered Oct 07 '22 22:10

Mohammed R. El-Khoudary