I’m actually using this working code and setting a trigger to repeat the task every 4 hours, but I would like to short the code checking every row, let’s say look for non empty rows in the range ‘A1:A20’.
What can be the short path to run the script without the use of this code?
function sendTelegramNotification() {
var sheet = SpreadsheetApp.getActive().getSheetByName("TELEGRAM");
if (sheet.getRange("A1").isBlank()) return;
var api = sheet.getRange("A1").getValues();
var group = sheet.getRange("B1").getValues();
var message = sheet.getRange("C1").getValues();
var url = 'https://api.telegram.org/bot' + api
+ '/sendMessage?chat_id=' + group
+ '&text=' + encodeURIComponent(message)
UrlFetchApp.fetch(url);
if (sheet.getRange("A2").isBlank()) return;
SpreadsheetApp.flush();
Utilities.sleep(80 * 100);
SpreadsheetApp.flush();
var api = sheet.getRange("A2").getValues();
var group = sheet.getRange("B2").getValues();
var message = sheet.getRange("C2").getValues();
var url = 'https://api.telegram.org/bot' + api
+ '/sendMessage?chat_id=' + group
+ '&text=' + encodeURIComponent(message)
UrlFetchApp.fetch(url);
if (sheet.getRange("A3").isBlank()) return;
//etc., etc.
}
2
Answers
I achieve it by using this code:
You could use getRange instead of
getDataRange()
forvar data = sheet.getDataRange().getValues();
and specify the rows and columns. Here is an example implementationUnfortunately I wasn’t able to test this due to limited access to Telegram Bot, but this should get you started.