Repository navigation
Expand file tree
/
Copy pathCodeAppsScript
More file actions
71 lines (64 loc) · 2.73 KB
/
Copy pathCodeAppsScript
File metadata and controls
71 lines (64 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
function onEdit(e) {
// Variáveis da planilha
var range = e.range;
var sheet = range.getSheet();
var localizacaoCelula = range.getA1Notation();
var coluna = localizacaoCelula[0];
var linha = parseInt(localizacaoCelula.substr(1));
var hora = sheet.getRange(`A${localizacaoCelula.substr(1)}`).getValue();
var dia = sheet.getRange(`${coluna}4`).getValue();
var nome, assunto;
// Verifique se a célula foi editada e se o evento é de duplo clique
if (linha % 2 == 1 && sheet.getRange(`${coluna}${parseInt(localizacaoCelula.substr(1)) + 1}`).getValue() !== "Assunto"){
nome = e.value;
assunto = sheet.getRange(coluna + (parseInt(localizacaoCelula.substr(1)) + 1)).getValue();
if (e.oldValue === "Nome"){
sendMessage(assunto.trim(), nome.trim(), hora, dia);
} else {
sendMessageAlter(assunto.trim(), nome.trim(), hora, dia);
}
} else if (linha % 2 == 0 && sheet.getRange(`${coluna}${parseInt(localizacaoCelula.substr(1)) - 1}`).getValue() !== "Nome"){
nome = sheet.getRange(coluna + (parseInt(localizacaoCelula.substr(1)) - 1)).getValue();
assunto = e.value;
if (e.oldValue === "Assunto"){
sendMessage(assunto.trim(), nome.trim(), hora, dia);
} else {
sendMessageAlter(assunto.trim(), nome.trim(), hora, dia);
}
}
}
// Variáveis do bot
var apiToken = "6597246012:AAEIIk28DEXGxECrjy0jBnlQ3OiR2nVvmdc";
var appUrl = "https://script.google.com/macros/s/AKfycbzGw5tERJRhu5mblfcNckR_mmATB5YRw3_Qq2iix3SDPt_0oUQsldC6_03Z3GVFbwJY/exec";
var apiUrl = "https://api.telegram.org/bot"+apiToken;
// set webhook: Código para linkar a API do Bot
function setWebhook(){
var url = apiUrl + "/setwebhook?url="+appUrl;
var res = UrlFetchApp.fetch(url).getContentText();
Logger.log(res);
}
// As seguintes funções são métodos para enviar as mensagens para o grupo, de acordo com o "chat_id" passado.
function sendMessage(assunto, nome, horario, dia){
var data = {
method: "post",
payload: {
method: "sendMessage",
chat_id: '-4010539847',
text: `Horário marcado:\nO(a) trainee ${nome} reservou um horário das ${horario} no dia ${dia}.\nO assunto da reunião será: "${assunto}"`,
parse_mode: "HTML",
}
};
var res = UrlFetchApp.fetch('https://api.telegram.org/bot' + apiToken + '/', data);
}
function sendMessageAlter(assunto, nome, horario, dia){
var data = {
method: "post",
payload: {
method: "sendMessage",
chat_id: '-4010539847',
text: `Correção:\nO(a) trainee ${nome} reservou um horário das ${horario} no dia ${dia}.\nO assunto da reunião será: "${assunto}"`,
parse_mode: "HTML",
}
};
var res = UrlFetchApp.fetch('https://api.telegram.org/bot' + apiToken + '/', data);
}