Verificación Webhook
Descripción general
Cuando un usuario responde a un mensaje, BotBell envía la respuesta a tu reply_url via HTTP POST. Verifica la firma para asegurar la autenticidad.
| Header de firma | X-Webhook-Signature: sha256=... |
| Header de timestamp | X-Webhook-Timestamp: 1234567890 |
Cómo funciona
- Extrae X-Webhook-Timestamp y X-Webhook-Signature de los headers
- Verifica que el timestamp esté dentro de 5 minutos (previene ataques de replay)
- Calcula HMAC-SHA256 de {timestamp}.{body} con tu webhook secret
- Compara con la firma (comparación en tiempo constante)
signature = HMAC-SHA256(
key: webhook_secret,
message: "{timestamp}.{request_body}"
)Python
from botbell import verify_webhook, WebhookVerificationError
try:
verify_webhook(
body=request.body,
signature_header=request.headers["X-Webhook-Signature"],
timestamp_header=request.headers["X-Webhook-Timestamp"],
secret="your_webhook_secret",
)
except WebhookVerificationError:
return {"error": "Invalid signature"}, 401
# Signature valid — process the reply
data = json.loads(request.body)JavaScript
import { verifyWebhook, WebhookVerificationError } from "@botbell/sdk";
try {
verifyWebhook({
body: req.body,
signature: req.headers["x-webhook-signature"],
timestamp: req.headers["x-webhook-timestamp"],
secret: "your_webhook_secret",
});
} catch (e) {
if (e instanceof WebhookVerificationError) {
return res.status(401).json({ error: e.message });
}
throw e;
}
// Signature valid — process the reply
const data = JSON.parse(req.body);