Automatizaciones

Webhooks para enviar SMS automáticos desde Google Sheets

No hay automatizaciones aún.

Conectar con Google Sheets

  1. 1Abre tu Google Sheet y ve a Extensiones → Apps Script
  2. 2Pega el siguiente código y reemplaza TU_URL con la URL del webhook
// Cambia esto al nombre exacto de tu hoja (pestaña)
const HOJAS = ["NombreHoja1", "NombreHoja2"];

// Columna P (16) = status, marca "Enviado" tras procesar
const COL_STATUS = 16;

function enviarSmsNuevos(e) {
  const sheet = e.source.getActiveSheet();
  if (!HOJAS.includes(sheet.getName())) return;

  const row = e.range.getRow();
  if (row <= 1) return;

  const status = sheet.getRange(row, COL_STATUS).getValue();
  if (status === "Enviado") return; // ya procesado

  const name = sheet.getRange(row, 14).getValue();
  let phone = sheet.getRange(row, 15).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 O (15) = Teléfono, Col P (16) = Status
  • Cambia NombreHoja1, NombreHoja2 por los nombres exactos de tus pestañas
  • Agrega el encabezado "Status" en P1 si no existe
  • Solo procesa filas NUEVAS — si P está vacío, envía y marca "Enviado"
  • Reemplaza TOKEN con el token de tu automatización