Step 1: Open Apps Script
Go to your Google Sheet, click on Extensions > Apps Script.
Step 2: Paste the Code
Delete any existing code and paste the script below into the editor.
const WEBHOOK_URL = 'https://google.waasender.com/webhook/google-sheets';
// --- CONFIGURATION ---
const SPECIFIC_SENDER_NUMBER = "";
const DEFAULT_COUNTRY_CODE = "966";
// If you want to FORCE a specific product name for this entire sheet (ignoring what's in the column)
// Enter it here. Leave blank "" to read from the column.
const OVERRIDE_PRODUCT_NAME = "";
// If you want to FORCE a specific message directly from this script (ignoring Dashboard templates)
// Enter it here. You can still use {name}, {product}, and {price}. Leave blank `` to use templates.
// EXAMPLE FORMAT (Notice the backticks ` instead of quotes " for multiple lines):
/*
const OVERRIDE_MESSAGE = `🍵TREYAS Super-Tea (شاي الشعر و الفروة)
Hello {name}, خلال الساعات القادمة سيتواصل معك أحد المختصين من فريق خدمة العملاء لشرح و الإجابة على أي استفسار لديك وتأكيد بيانات الشحن قبل إرسال الطلب .
شكراً لثقتك.`;
*/
const OVERRIDE_MESSAGE = ``;
// COLUMN NUMBERS (Based on your screenshot)
// A=1, B=2, C=3, D=4, E=5, F=6, G=7, H=8, I=9, J=10, K=11, L=12, M=13, N=14
const COL_ORDER_DATE = 1;
const COL_ORDER_ID = 2;
const COL_NAME = 3; // First name
const COL_PHONE = 4; // Phone
const COL_COUNTRY = 5;
const COL_CITY = 6;
const COL_ADDRESS = 7;
const COL_PRODUCT = 8; // Product variant
const COL_SKU = 9;
const COL_QUANTITY = 10;
const COL_PRICE = 11; // Total with custom
const COL_CURRENCY = 12; // Order customer currency
const COL_STATUS = 14; // Column N: We will write "Sent" or "Failed" here
// You can use this for "On Edit", "On Change", OR "On Form Submit"
function onChangeTrigger(e) {
try {
let sheet, row;
// Handle "On Edit" or "On Form Submit"
if (e && e.range) {
sheet = e.range.getSheet();
row = e.range.getRow();
}
// Handle "On Change"
else {
sheet = SpreadsheetApp.getActiveSheet();
const activeRange = SpreadsheetApp.getActiveRange();
if (activeRange) {
row = activeRange.getRow();
} else {
row = sheet.getLastRow();
}
}
// Read data from your specific columns
const order_date = sheet.getRange(row, COL_ORDER_DATE).getValue();
const order_id = sheet.getRange(row, COL_ORDER_ID).getValue();
const name = sheet.getRange(row, COL_NAME).getValue();
const phone = sheet.getRange(row, COL_PHONE).getValue();
const country = sheet.getRange(row, COL_COUNTRY).getValue();
const city = sheet.getRange(row, COL_CITY).getValue();
const address = sheet.getRange(row, COL_ADDRESS).getValue();
const sheetProduct = sheet.getRange(row, COL_PRODUCT).getValue();
const sku = sheet.getRange(row, COL_SKU).getValue();
const quantity = sheet.getRange(row, COL_QUANTITY).getValue();
const price = sheet.getRange(row, COL_PRICE).getValue();
const currency = sheet.getRange(row, COL_CURRENCY).getValue();
const status = sheet.getRange(row, COL_STATUS).getValue();
const product = (OVERRIDE_PRODUCT_NAME && OVERRIDE_PRODUCT_NAME !== "") ? OVERRIDE_PRODUCT_NAME : sheetProduct;
// Ensure it's not the header row, and phone exists
if (row > 1 && phone && phone !== "") {
// Don't send again if already sent
if (status && String(status).includes("Sent")) {
return;
}
let cleanPhone = String(phone).replace(/[^0-9]/g, '');
// Auto-format country code
if (DEFAULT_COUNTRY_CODE && DEFAULT_COUNTRY_CODE !== "") {
if (cleanPhone.startsWith('0')) {
cleanPhone = DEFAULT_COUNTRY_CODE + cleanPhone.substring(1);
} else if (!cleanPhone.startsWith(DEFAULT_COUNTRY_CODE)) {
cleanPhone = DEFAULT_COUNTRY_CODE + cleanPhone;
}
}
// Send to Server
const payload = {
"phoneNumber": cleanPhone,
"name": String(name),
"productName": String(product),
"price": String(price),
"order_date": String(order_date),
"order_id": String(order_id),
"country": String(country),
"city": String(city),
"address": String(address),
"sku": String(sku),
"quantity": String(quantity),
"currency": String(currency),
"message": ""
};
if (OVERRIDE_MESSAGE && OVERRIDE_MESSAGE !== "") {
payload.message_override = String(OVERRIDE_MESSAGE);
}
if (SPECIFIC_SENDER_NUMBER && SPECIFIC_SENDER_NUMBER !== "") {
payload.sender_session_id = String(SPECIFIC_SENDER_NUMBER);
}
const options = {
'method': 'post',
'contentType': 'application/json',
'payload': JSON.stringify(payload),
'muteHttpExceptions': true
};
const response = UrlFetchApp.fetch(WEBHOOK_URL, options);
try {
const result = JSON.parse(response.getContentText());
if (result.success) {
if (result.message && result.message.includes('queued')) {
sheet.getRange(row, COL_STATUS).setValue("Queued: " + result.message);
} else {
sheet.getRange(row, COL_STATUS).setValue(result.message_sent || "Sent");
}
} else {
sheet.getRange(row, COL_STATUS).setValue("Failed: " + (result.error || "Unknown Error"));
}
} catch (e) {
sheet.getRange(row, COL_STATUS).setValue("Sent but failed to read response");
}
}
} catch (error) {
console.error("Webhook error: " + error);
}
}
Step 3: Add a Trigger
Click the clock icon (Triggers) on the left side of Apps Script. Add a new trigger:
Function: onChangeTrigger
Event Source: From spreadsheet
Event Type: On change (For Zapier/APIs) or On form submit (For Google Forms)
Step 4: Save & Authorize
Save the trigger, click "Advanced", and grant permissions to your Google Account. You're done!