r/GoogleAppsScript • u/Opposite_Actuator118 • Feb 21 '26
Question Script Help
I have created a script on my google sheet to send a message using a webhook. Currently the script constant data is “text”: “include message” so when it runs “include message” pops up in the chat.
What do I need to change in my scripting so that “include message” can be replaced with new values from the google sheet.
I need the script to run every-time a new row is added to the sheet (this is occurring) with the message being the contents of the new row.
Thanks!
1
Upvotes
View all comments
Show parent comment
1
u/Opposite_Actuator118 Feb 21 '26
I ended up asking an AI and I’m glad I did, it was all types of messed up. Finally code read as such:
const WEBHOOK_URL = "PASTE_YOUR_WEBHOOK_URL_HERE";
function sendWebhookMessage() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet(); const lastRow = sheet.getLastRow();
// Headers (Row 1, Columns C-H) const headers = sheet.getRange(1, 3, 1, 6).getValues()[0];
// Data (Last Row, Columns C-H) const rowData = sheet.getRange(lastRow, 3, 1, 6).getValues()[0];
let messageLines = [];
for (let i = 0; i < headers.length; i++) { if (rowData[i] !== "" && rowData[i] !== null) { messageLines.push(headers[i] + ": " + rowData[i]); } }
// If everything was blank, don't send anything if (messageLines.length === 0) { return; }
const data = { text: messageLines.join("\n") };
const options = { method: "post", contentType: "application/json", payload: JSON.stringify(data) };
UrlFetchApp.fetch(WEBHOOK_URL, options); }