Webhooks
Registra una URL HTTPS, elige eventos y verifica la firma. Octuvia entrega cada evento firmado; si tu endpoint falla, reintenta y puedes reconciliar con GET /events.
Los webhooks son del workspace (no de un número concreto). Filtras por events, y opcionalmente por platforms, profile_ids o account_ids.
Endpoints
| Endpoint | Uso |
|---|---|
| Listar endpoints | GET /webhook-endpoints |
| Crear endpoint | POST — guarda el signing_secret |
| Actualizar endpoint | PATCH — url, events, status… |
| Eliminar endpoint | DELETE — cancela entregas pendientes |
| Rotar secreto | POST …/rotate-secret — doble firma 24 h |
| Probar endpoint | POST …/test — envía webhook.test |
| Listar eventos | GET /events — reconciliación |
| Entregas de un evento | GET /events/{id}/deliveries |
| Reintentar entrega | POST /webhook-deliveries/{id}/retry |
Firma
| Header | Qué es |
|---|---|
X-Octuvia-Event-Id | Id del evento (evt_…). Deduplica con este valor. |
X-Octuvia-Delivery-Id | Id de la entrega (whd_…). |
X-Octuvia-Attempt | 1 = primer intento; hasta 5 (1 min, 5 min, 30 min, 2 h). |
X-Octuvia-Timestamp | Epoch en segundos. Rechaza si |now − ts| > 5 min. |
X-Octuvia-Signature | v1=hex(HMAC_SHA256(secret, "<ts>." + raw_body)). En rotación: v1=nuevo,v1=anterior. |
const crypto = require("crypto");
function verifyWebhook(rawBody, headers, signingSecret) {
const ts = headers["x-octuvia-timestamp"];
const sigHeader = headers["x-octuvia-signature"] || "";
if (!ts || !sigHeader) return false;
if (Math.abs(Date.now() / 1000 - Number(ts)) > 300) return false;
const expected =
"v1=" +
crypto.createHmac("sha256", signingSecret).update(`${ts}.${rawBody}`).digest("hex");
return sigHeader.split(",").some((part) => {
try {
return crypto.timingSafeEqual(Buffer.from(part.trim()), Buffer.from(expected));
} catch {
return false;
}
});
}Responde 2xx rápido
Octuvia espera HTTP 2xx. Si fallas: reintentos a 1 min, 5 min, 30 min y 2 h; luegodead. Tras varios días sin éxito el endpoint puede pasar a disabled_by_failures (reactívalo con PATCH).Envelope de cada evento
Todas las entregas usan el mismo envelope. Cambia type y data. data.object es el recurso (mismo shape que su GET); en cambios también puede venir data.previous_attributes. request es tu petición (req_…) o null si lo originó WhatsApp/el sistema.
{
"object": "event",
"id": "evt_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"type": "<event.type>",
"api_version": "v1",
"created_at": "2026-12-03T22:33:00.000Z",
"livemode": true,
"profile_id": "prf_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform": "whatsapp",
"data": {
"object": {
"object": "<message|account|template|…>",
"id": "…"
},
"previous_attributes": {
"status": "PENDING"
}
},
"request": null
}Catálogo de eventos
Puedes suscribirte a tipos exactos, familias (message.*, account.*, whatsapp.*) o *. Debajo de cada familia: el JSON completo que llega a tu URL.
Mensajes
| Evento | Cuándo |
|---|---|
message.received | Entrante (texto, media, interactivo, etc.) |
message.sent | Saliente aceptado por WhatsApp (source: api | native_app | …) |
message.delivered | Entregado al contacto |
message.read | Leído por el contacto |
message.failed | Falló el envío/entrega (data.object.error) |
message.revoked | Borrado para todos (coexistencia) |
message.edited | Texto editado (coexistencia) |
message.reaction | Reacción added | removed |
{
"object": "event",
"id": "evt_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"type": "message.received",
"api_version": "v1",
"created_at": "2026-12-03T22:33:00.000Z",
"livemode": true,
"profile_id": "prf_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform": "whatsapp",
"data": {
"object": {
"object": "message",
"id": "msg_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"conversation_id": "conv_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"profile_id": "prf_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform": "whatsapp",
"platform_message_id": "wamid.HBgLNTE5ODc2NTQzMjEVAgARGBIAAA",
"direction": "inbound",
"source": null,
"from": "+51987654321",
"to": "+15556433682",
"contact": {
"id": "+51987654321",
"name": "Ana Pérez",
"whatsapp": {
"wa_id": "51987654321"
}
},
"type": "text",
"content": {
"text": {
"body": "Hola"
}
},
"reply_to": null,
"status": "delivered",
"error": null,
"metadata": {},
"request_id": null,
"created_at": "2026-12-03T22:33:00.000Z",
"sent_at": null,
"delivered_at": "2026-12-03T22:33:00.000Z",
"read_at": null,
"failed_at": null
}
},
"request": null
}Conversaciones y conversiones
| Evento | Cuándo |
|---|---|
conversation.created | Primer mensaje con un contacto en un número |
conversation.attribution_added | Clic en anuncio Click-to-WhatsApp |
conversion.sent | Meta aceptó la conversión |
conversion.failed | Meta rechazó la conversión |
{
"object": "event",
"id": "evt_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"type": "conversation.created",
"api_version": "v1",
"created_at": "2026-12-03T22:33:00.000Z",
"livemode": true,
"profile_id": "prf_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform": "whatsapp",
"data": {
"object": {
"object": "conversation",
"id": "conv_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"profile_id": "prf_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform": "whatsapp",
"contact": {
"id": "+51987654321",
"name": "Ana Pérez",
"whatsapp": {
"wa_id": "51987654321"
}
},
"status": "open",
"unread_count": 1,
"last_message_at": "2026-12-03T22:33:00.000Z",
"last_inbound_at": "2026-12-03T22:33:00.000Z",
"window_expires_at": "2026-12-04T22:33:00.000Z",
"free_window_expires_at": null,
"first_attribution": null,
"last_attribution": null,
"attributions_count": 0,
"metadata": {},
"created_at": "2026-12-03T22:33:00.000Z",
"updated_at": "2026-12-03T22:33:00.000Z"
}
},
"request": null
}Cuentas
| Evento | Cuándo |
|---|---|
account.connected | Número conectado (connect link o BYO) |
account.updated | Cambió calidad, tier, throughput o nombre verificado |
account.reauthorization_required | Token/webhooks revocados; hay que reconectar |
account.disconnected | Número desconectado |
{
"object": "event",
"id": "evt_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"type": "account.connected",
"api_version": "v1",
"created_at": "2026-12-03T22:33:00.000Z",
"livemode": true,
"profile_id": "prf_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform": "whatsapp",
"data": {
"object": {
"object": "account",
"id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"profile_id": "prf_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform": "whatsapp",
"status": "connected",
"connection_method": "connect_link",
"name": "Clínica Sonrisa — Ventas",
"reference": "clinica-ventas",
"capabilities": {
"templates": true,
"reactions": true,
"typing_indicator": true,
"read_receipts": true,
"calling": false,
"conversions": true
},
"whatsapp": {
"phone_number": "+15556433682",
"verified_name": "Clínica Sonrisa",
"waba_id": "102938475610293",
"phone_number_id": "109876543210987",
"quality_rating": "GREEN",
"messaging_limit_tier": "TIER_1K",
"throughput": "STANDARD",
"coexistence": false
},
"metadata": {},
"connected_at": "2026-11-01T10:00:00.000Z",
"created_at": "2026-11-01T10:00:00.000Z",
"updated_at": "2026-12-03T22:33:00.000Z"
}
},
"request": null
}WhatsApp (avisos finos)
| Evento | Cuándo |
|---|---|
whatsapp.template.status_changed | Plantilla APPROVED / REJECTED / PAUSED / … |
whatsapp.template.status_updated | Alias de status_changed |
whatsapp.template.category_updated | Meta reclasificó la categoría |
whatsapp.call_permission.updated | Permiso de llamada granted | revoked |
whatsapp.account.quality_updated | Calidad GREEN / YELLOW / RED |
whatsapp.account.name_status_updated | Nombre verificado o decisión de review |
whatsapp.account.status_updated | Tier, throughput o restricción |
whatsapp.account.alert_received | Alerta Meta (account_alerts / violaciones) |
whatsapp.contact.identity_changed | El contacto cambió de número/identidad |
whatsapp.number.activated | Número activado o nombre aprobado |
whatsapp.number.declined | Nombre o revisión rechazada |
whatsapp.number.action_required | Meta exige una acción |
whatsapp.number.verification_required | Verificación de negocio pendiente |
whatsapp.number.suspended | Número/cuenta restringida |
whatsapp.number.reactivated | Reactivado tras review |
whatsapp.number.released | Número liberado o eliminado del WABA |
whatsapp.number.kyc_submitted | KYC / review enviado |
whatsapp.automatic_event | Evento Meta no clasificado (incluye meta_event) |
account.updated sigue emitiéndose cuando cambia calidad/nombre/tier. Los whatsapp.account.* y whatsapp.number.* son el desglose fino (paridad tipo Zernio).
{
"object": "event",
"id": "evt_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"type": "whatsapp.template.status_changed",
"api_version": "v1",
"created_at": "2026-12-03T22:33:00.000Z",
"livemode": true,
"profile_id": "prf_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform": "whatsapp",
"data": {
"object": {
"object": "template",
"id": "tpl_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform_template_id": "123456789012345",
"name": "pedido_enviado",
"language": "es",
"category": "UTILITY",
"status": "APPROVED",
"rejection_reason": null,
"quality_score": "GREEN",
"components": [
{
"type": "BODY",
"text": "Hola {{1}}, tu pedido {{2}} ya salió."
}
],
"created_at": "2026-11-20T12:00:00.000Z",
"updated_at": "2026-12-03T22:33:00.000Z"
},
"previous_attributes": {
"status": "PENDING"
}
},
"request": null
}Prueba
| Evento | Cuándo |
|---|---|
webhook.test | POST /webhook-endpoints/{id}/test |
{
"object": "event",
"id": "evt_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"type": "webhook.test",
"api_version": "v1",
"created_at": "2026-12-03T22:33:00.000Z",
"livemode": true,
"profile_id": "prf_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"account_id": "acc_01J8Z3K4M5N6P7Q8R9S0T1U2V3",
"platform": "whatsapp",
"data": {
"object": {
"object": "webhook_test",
"webhook_endpoint_id": "whe_01J8Z3K4M5N6P7Q8R9S0T1U2V3"
}
},
"request": null
}