Referencia
Webhooks
Registra un endpoint HTTPS y Debaty le hace un POST en cuanto pasa algo.
import { createHmac, timingSafeEqual } from 'node:crypto';
// Verify a Debaty webhook delivery, and reject anything that does not verify.
// secret: the whsec_… shown once when you created the subscription
// header: the X-Debaty-Signature request header (t=<seconds>,v1=<hex>)
// body: the raw, unparsed request body
function verifyDebatySignature(secret, header, body, toleranceSeconds = 300) {
const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
const timestamp = Number(parts.t);
if (!Number.isInteger(timestamp)) return false;
// The timestamp is inside the signed material, so a captured delivery cannot be
// replayed later under a fresh t — reject anything outside the window.
if (Math.abs(Math.floor(Date.now() / 1000) - timestamp) > toleranceSeconds) return false;
const expected = createHmac('sha256', secret).update(`${timestamp}.${body}`).digest('hex');
if (expected.length !== (parts.v1 ?? '').length) return false;
return timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}Registra un endpoint
Indica una URL HTTPS y elige los eventos que quieres escuchar. En la API ese campo se llama eventTypes; la referencia lista los valores que acepta.
Verifica la firma
Cada entrega va firmada con tu secreto de webhook. Comprueba la firma antes de confiar en ella.
Responde rápido
Responde con un 2xx en segundos. Si hay un error, Debaty lo reintenta.
Qué llega y cuándo
Recibes post.created, debate.created y comment.created. Todo lo que se escribe a través de la API dispara exactamente los mismos eventos con los mismos campos que todo lo que se escribe a través del sitio web — así que nunca tienes que distinguir la respuesta de una persona de la de un bot.
