-
Notifications
You must be signed in to change notification settings - Fork 0
/
main script.js
57 lines (45 loc) · 1.7 KB
/
main script.js
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
function getData() {
var sheetId = "1X515mLf7AjlCb7FYqjj2zaswL2W51vlwSbRF9he9T88";
var currentSheet = SpreadsheetApp.openById(sheetId).getSheetByName("Form Responses 1");
var lastRow = currentSheet.getLastRow();
var lastColumn = currentSheet.getLastColumn();
Logger.log("Last Row :" + lastRow);
Logger.log("Last Column :" + lastColumn);
var headerData = currentSheet.getRange("H1:I1").getValues()[0];
var lastRowData = currentSheet.getRange("H" + lastRow + ":I" + lastRow).getValues()[0];
Logger.log("Header :" + headerData);
Logger.log("Last Row Data :" + lastRowData);
//set message
var message = "\n\n" + "ชิบหายแล้วทุกคนนนน มีเรื่อง(ร้องเรียน)แล้วววววว วี้หว่อๆๆๆ🚨🚨";
for (var i = 0; i < headerData.length; i++) {
message += "\n\n" + "📩" + headerData[i] + " : " + lastRowData[i];
}
Logger.log("Data Message :" + message);
//set line notify
if (message !== "") {
sendMessage(message);
}
}
function sendMessage(message) {
var lineNotifyEndPoint = "https://notify-api.line.me/api/notify";
var accessToken = "4JLVBMKaXaGx2rXOhtV9u0J0nXJhf7GHlCGTHnTd8iQ";
var formData = {
"message": message,
"stickerPackageId": "446",
"stickerId": "2006"
};
var options = {
"headers" : {"Authorization" : "Bearer " + accessToken},
"method" : 'post',
"payload" : formData
};
try {
var response = UrlFetchApp.fetch(lineNotifyEndPoint, options);
} catch (error) {
Logger.log(error.name + ":" + error.message);
return;
}
if (response.getResponseCode() === 200) {
Logger.log("Sending message completed.");
}
}