0
votes

I have a table with data and I need a telegram message to be sent when the checkbox is installed in the H:H column. I found a script that sends messages, on how to configure it to take data only on the active line and trigger the click on the checkbox? Help, please

Table: https://docs.google.com/spreadsheets/d/16wAenoFtUtYXUZg6LKmTyzKRFL8WuHlB5qAGtUltzhY/edit#gid=2119848803 Script: https://pastebin.com/z4NsqR4z

const token = "";
 
function timer() {
  let ss = SpreadsheetApp.getActiveSpreadsheet();
  let ws = ss.getSheetByName("Авансы");
  let activeCell = ss.getActiveSheet().getActiveCell();
  let data = ws.getRange(2, 1, ws.getLastRow()-1, 9).getValues();
 
  for (i = 0; i < data.length; i++) {
    let dataInfo = data[i];
    let partner = dataInfo[0];
    let inn = dataInfo[1];
    let order = dataInfo[3]; 
    let data_order = dataInfo[4];
    let sum_prepayment = dataInfo[5]; 
    let request_sent = dataInfo [7];
    let data_request_sent = dataInfo [8];
    let credited_prepayment = dataInfo [9];
    let data_credited_prepayment = dataInfo [10];
    let executor = dataInfo [11];
    let chatID = "";

    if (request_sent === true && data_request_sent === "") {
      sendText(chatID, "Отправлен запрос, контрагенту  " + partner + " (ИНН " + inn + " ). По заказу: " + order + " от "+ data_order + ", сумма аванса:" + sum_prepayment +
                            " руб. Запрос отправил: " + executor + " .");
      }
    
//console.log(sendText)   
    if (credited_prepayment === true && data_credited_prepayment === "") {
      sendText(chatID, "Аванс в размере" + sum_prepayment + " руб., по заказу " + order + " от  " + data_order + "г. ЗАЧТЕН. ");
    }    
  }
//console.log(sendText)
}
 

  if (value && range.getColumn() == 2 && sheet.getName() == 'Лист1') {
    function sendText(chatId, text, keyBoard) {

    let data = {
      method: 'post',
      payload: {
        method: 'sendMessage',
        chat_id: String(chatId),
        text: text,
        parse_mode: 'HTML',
        reply_markup: JSON.stringify(keyBoard)
      }
    }  
    UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/', data);
  }
}
What's the question? - Cooper