Created
August 5, 2018 17:49
-
-
Save sergiks/2849bc024edfaa15f79185d725fa9879 to your computer and use it in GitHub Desktop.
Google Apps Script Telegram bot parts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function TelegramClient(token) { | |
var _token = token; | |
this.getURL = function() { | |
return "https://api.telegram.org/bot" + _token; | |
} | |
this.getResponse = function( method, data) { | |
var response = UrlFetchApp | |
.fetch( | |
this.getURL() + '/' + method | |
,{method: "post", payload: data} | |
) | |
; | |
// Logger.log( "Telegram: " + response.getResponseCode()); | |
return response; | |
} | |
this.getMe = function() { | |
return this.getResponse("getMe").getContentText(); | |
} | |
this.getFile = function(file_id) { | |
return this.getResponse("getFile", {file_id: file_id}).getContentText(); | |
} | |
this.setWebhook = function(url) { | |
return this.getResponse("setWebhook", {url: url}).getContentText(); | |
} | |
this.getWebhookInfo = function() { | |
return this.getResponse("getWebhookInfo").getContentText(); | |
} | |
this.sendMessage = function(chatId, text, parse_mode) { | |
parse_mode = parse_mode || ''; | |
return this.getResponse("sendMessage", {chat_id: ''+chatId, text: text, parse_mode: parse_mode}).getContentText(); | |
} | |
this.sendMessageRaw = function(options) { | |
return this.getResponse("sendMessage", options).getContentText(); | |
} | |
this.sendPhoto = function(chatId, photo, caption) { | |
return this.getResponse("sendPhoto", {chat_id: ''+chatId, photo: photo, caption: caption || ""}).getContentText(); | |
} | |
this.sendDocument = function(chatId, document, caption) { | |
return this.getResponse("sendDocument", {chat_id: ''+chatId, document: document, caption: caption || ""}).getContentText(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment