Advertisement
ZiGoomul

Отправка сообщений из Google таблиц в телеграмм по времени

Nov 14th, 2020
3,801
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const token = "Токен вашего бота";
  2.  
  3. function timer() {
  4.   let ss = SpreadsheetApp.getActiveSpreadsheet();
  5.   let ws = ss.getSheetByName("Клиенты");
  6.   let data = ws.getRange(2, 2, ws.getLastRow()-1, 6).getValues();
  7.   let curentTime = new Date().getDate() + "." + (new Date().getMonth() + 1) + "." + new Date().getFullYear();
  8.  
  9.   for (i = 0; i < data.length; i++) {
  10.     let dataInfo = data[i];
  11.     let clientName = dataInfo[1];
  12.     let clientBirthday  = dataInfo[4].toString();
  13.     let clientIdChat = dataInfo[5];
  14.     if (dataInfo[4] !== ""){
  15.       clientBirthday = dataInfo[4].getDate() + "." + (dataInfo[4].getMonth() + 1) + "." + dataInfo[4].getFullYear();
  16.       console.log(clientIdChat)
  17.     }
  18.     if (clientBirthday === curentTime){
  19.       if (clientIdChat !== ""){
  20.         sendText(clientIdChat, "Уважаемый, " + clientName + ". Поздравляем вас с Днем Рождения!!!🎂");
  21.       }
  22.     }
  23.   }
  24. //console.log(curentTime)
  25. }
  26.  
  27. function sendText(chatId, text, keyBoard) {
  28.   let data = {
  29.     method: 'post',
  30.     payload: {
  31.       method: 'sendMessage',
  32.       chat_id: String(chatId),
  33.       text: text,
  34.       parse_mode: 'HTML',
  35.       reply_markup: JSON.stringify(keyBoard)
  36.     }
  37.   }
  38.   UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/', data);
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement