Created
February 1, 2020 11:54
-
-
Save jagedn/6af695be7384892eb1fe6506ad41075c to your computer and use it in GitHub Desktop.
feed telegram channel with google sheet
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 telegram(){ | |
var bot = 'XXXXXX:YYYYYYYYYYYYY' | |
var chatId = 'CHANNEL_ID' | |
var url = 'https://api.telegram.org/bot'+bot | |
var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = ss.getActiveSheet(); | |
var rangeData = sheet.getDataRange(); | |
var lastColumn = rangeData.getLastColumn(); | |
var lastRow = rangeData.getLastRow(); | |
var searchRange = sheet.getRange(2,1, lastRow, lastColumn); | |
var rangeValues = searchRange.getValues(); | |
for ( i = 0; i < lastRow-1 ; i++){ | |
if( rangeValues[i][0] ) | |
continue; | |
var text = '*' + rangeValues[i][1] + '*\n' | |
text+= rangeValues[i][2] | |
var options = { | |
'method' : 'post', | |
'payload' : { | |
"chat_id": chatId, | |
"parse_mode": "MarkdownV2", | |
"text": text | |
} | |
}; | |
UrlFetchApp.fetch(url+'/sendMessage', options); | |
if( rangeValues[i][3] != "" ){ | |
var options = { | |
'method' : 'post', | |
'payload' : { | |
"chat_id": chatId, | |
"photo": rangeValues[i][3] | |
} | |
}; | |
Logger.log(options) | |
UrlFetchApp.fetch(url+'/sendPhoto', options); | |
} | |
sheet.getRange("A"+(2+i)).setValue("true") | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment