Google Sheets
- 13 ответов
- 0 вопросов
6
Вклад в тег
function sendMessage(from_chat_id, text, keyboard, id_msg) { // Отправляет сообщение используя sendMessage
var data = {
method: "sendMessage",
chat_id: String(from_chat_id),
text: text,
parse_mode: "HTML",
reply_markup: JSON.stringify(keyboard),
reply_to_message_id: String(id_msg)
};
var options = {
method: 'POST',
payload: data,
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/sendMessage', options);
console.log(JSON.parse(response.getContentText(), null, 7))
}
let keyboard_contact = {
keyboard: [
[{
text: "Авторизоваться",
request_contact: true
}]
],
resize_keyboard: true,
one_time_keyboard: true
};
let keyboard_menu_inline = {
inline_keyboard: [
[{
text: "Услуги ",
callback_data: "services"
}, {
text: "Оплата ",
url: "https://google.com",
callback_data: "pay"
}],
[{
text: "Статус ✅ ",
url: "https://google.com"
}, {
text: "Обратная связь ",
callback_data: "support"
}]
]
};
sendMessage(from_chat_id, text, keyboard)
function onEdit(e) {
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let row = e.range.getRow();
let column = e.range.getColumn();
let value = e.source.getActiveSheet().getRange(row, 1).getValue();
let checkbox = SpreadsheetApp.newDataValidation().requireCheckbox().setAllowInvalid(false).build();
if (column == 1 && value !== "") {
sheet.getRange(row, 2).setDataValidation(checkbox).setValue(false);
}
}
let ID = "<id вашей папки>";
function createFolder() {
let mainFolder = DriveApp.getFolderById(ID);
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let foldersNames = sheet.getRange(2, 1, sheet.getLastRow(), 3).getValues();
let folders = mainFolder.getFolders();
let arr = [];
while (folders.hasNext()) {
let folder = folders.next();
arr.push({
"name": folder.getName(),
"folderID": folder.getId(),
"lastUpdated": folder.getLastUpdated()
})
}
let res = arr.map(item => item.name);
foldersNames.forEach((el, index) => {
if (typeof el[0] === "string" && res.indexOf(el[0]) === -1 && el[0] != "") {
let nFolder = mainFolder.createFolder(el[0]);
sheet.getRange(index + 2, 2, 1, 2).setValues([[nFolder.getId(), nFolder.getLastUpdated()]]);
console.log(`New folder created!
name: ${el[0]}
creation date: ${nFolder.getLastUpdated()}
`)
}
})
}
function downloadData() {
let mainFolder = DriveApp.getFolderById(ID);
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let foldersNames = sheet.getRange(2, 1, sheet.getLastRow(), 3).getValues().map(item => item[0]);
let folders = mainFolder.getFolders();
let arr = [];
while (folders.hasNext()) {
let folder = folders.next();
arr.push({
"name": folder.getName(),
"folderID": folder.getId(),
"lastUpdated": folder.getLastUpdated()
})
}
arr.forEach(el => {
if (foldersNames.indexOf(el.name) === -1 && foldersNames.indexOf(el.folderID) === -1) {
sheet.getRange(sheet.getLastRow() + 1, 1, 1, 3).setValues([[el.name, el.folderID, el.lastUpdated]]);
}
})
console.log(arr)
}
function onEdit(e){
let row = e.range.getRow();
let column = e.range.getColumn();
let cache = CacheService.getScriptCache();
cache.putAll({
"row": `${row}`,
"column": `${column}`
});
}
function onOpen() {
let cache = CacheService.getScriptCache();
let sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
let row = cache.get("row");
let column = cache.get("column");
sheet.getRange(+row, +column).activate();
SpreadsheetApp.flush();
}