Telegram API with Google Apps Script

旧时模样 提交于 2019-12-09 06:02:54

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/21967762/telegram-api-with-google-apps-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!