Webhooks

Recibe notificaciones cuando ocurren eventos en AtiendeApp.

Eventos disponibles

  • message.received — Mensaje entrante de un contacto
  • message.sent — Mensaje enviado vía API
  • webhook.test — Evento de prueba manual

Payload

{
  "event": "message.received",
  "timestamp": "2026-05-17T14:30:00Z",
  "data": {
    "from": "56912345678",
    "message": "Hola necesito una cita",
    "instance_id": "uuid-instancia",
    "contact_name": "Juan Pérez"
  }
}

Verificar firma HMAC

Cada webhook incluye estos headers de seguridad:

X-AtiendeApp-Signature: sha256=<hmac_hex>
X-AtiendeApp-Timestamp: <unix_timestamp>
X-AtiendeApp-Event: message.received

Verifica la firma así:

Node.js — verificar firma
const crypto = require('crypto');

function verifyWebhook(req, webhookSecret) {
  const signature = req.headers['x-atiendeapp-signature'];
  const timestamp = req.headers['x-atiendeapp-timestamp'];

  // Reject if timestamp is older than 5 minutes (anti-replay)
  if (Math.abs(Date.now() / 1000 - parseInt(timestamp)) > 300) {
    return false;
  }

  const body = JSON.stringify(req.body);
  const expected = 'sha256=' + crypto
    .createHmac('sha256', webhookSecret)
    .update(`${timestamp}.${body}`)
    .digest('hex');

  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expected)
  );
}

Reintentos automáticos

Si tu endpoint no responde con 2xx en 10 segundos, AtiendeApp reintenta:

IntentoEspera
1ro1 minuto
2do5 minutos
3ro (último)30 minutos → si falla: marcado como failed