-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSheetFunction.js
More file actions
45 lines (38 loc) · 1.16 KB
/
SheetFunction.js
File metadata and controls
45 lines (38 loc) · 1.16 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
function SendUpdateOnAddorEdit(e) {
const sheet = e.source.getActiveSheet();
const range = e.range;
const lastRow = sheet.getLastRow();
// Only run if the edited row is the last row (new data)
if (range.getRow() !== lastRow) return;
// Get the row data
const rowData = sheet.getRange(lastRow, 1, 1, 4).getValues()[0]; // Assuming 4 columns: ID, Name, Email, Phone
const [id, name, email, phone] = rowData;
// Only proceed if all required fields are filled
if (!id || !name || !email || !phone) return;
const payload = {
from: "demo123",
tempName: "temp1",
data: [
{
id: id,
name: name,
email: email,
phone: phone
}
]
};
const url = 'https://autosetu.onrender.com/send-whatsapp';
const options = {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(payload),
muteHttpExceptions: true,
};
try {
const resp = UrlFetchApp.fetch(url, options);
console.log("Response Code:", resp.getResponseCode());
console.log("Response Body:", resp.getContentText());
} catch (error) {
console.error("Error while sending request:", error);
}
}