Automatizaciones
Webhooks para enviar SMS automáticos desde Google Sheets
No hay automatizaciones aún.
Conectar con Google Sheets
- 1Abre tu Google Sheet y ve a Extensiones → Apps Script
- 2Pega el siguiente código y reemplaza
TU_URLcon la URL del webhook
// Cambia esto al nombre exacto de tu hoja (pestaña)
const HOJAS = ["NombreHoja1", "NombreHoja2"];
// Columna R (18) = status, marca "Enviado" tras procesar
const COL_STATUS = 18;
function enviarSmsNuevosE(e) {
// Validar que el evento sea por insertar fila o editar
if (e && e.changeType !== 'INSERT_ROW' && e.changeType !== 'EDIT') return;
const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
if (!HOJAS.includes(sheet.getName())) return;
const lastRow = sheet.getLastRow();
for (let row = 2; row <= lastRow; row++) {
const status = sheet.getRange(row, COL_STATUS).getValue();
if (status === "Enviado") continue; // ya procesado
const name = sheet.getRange(row, 14).getValue();
let phone = sheet.getRange(row, 16).getValue();
// Limpia formato (ej: "p:+1415..." -> "+1415...")
phone = String(phone).replace(/^p:/, "").trim();
if (name && phone) {
try {
UrlFetchApp.fetch(
"https://sms.intiwasischool.com/api/automations/webhook/TOKEN",
{
method: "POST",
contentType: "application/json",
payload: JSON.stringify({ name, phone }),
muteHttpExceptions: true,
}
);
sheet.getRange(row, COL_STATUS).setValue("Enviado");
} catch (err) {
sheet.getRange(row, COL_STATUS).setValue("Error");
}
}
}
}Configuración:
- Col N (14) = Nombre, Col P (16) = Teléfono, Col R (18) = Status
- Cambia
NombreHoja1,NombreHoja2por los nombres exactos de tus pestañas - Agrega el encabezado "Status" en R1 si no existe
- Escanea todas las filas de la hoja — si R está vacío, envía y marca "Enviado"
- Reemplaza
TOKENcon el token de tu automatización - Si tienes múltiples hojas, duplica la función con nombre distinto (ej:
enviarSmsNuevosE2) y crea triggers separados