Webhook
Resumen
Sección titulada «Resumen»El provider de eventos Webhook permite que tu trabajador digital reciba webhooks HTTP de servicios externos como GitHub, Stripe, Shopify, etc.
Configuración
Sección titulada «Configuración»-
Configura el Provider
answers.json {"events-webhook": {"enabled": true,"public_base_url": "https://your-domain.ngrok-free.app"}} -
Ejecuta la configuración
Ventana de terminal gtc setup --answers answers.json ./my-bundle -
Registra el Webhook
Usa la URL de webhook generada en tu servicio externo:
https://your-domain.com/events/webhook/{tenant}/{event_type}
Opciones de configuración
Sección titulada «Opciones de configuración»| Opción | Requerido | Descripción |
|---|---|---|
enabled | Sí | Habilita/deshabilita el provider |
public_base_url | Sí | URL pública para los webhooks |
secret_header | No | Nombre del header para la validación de firmas |
secret_key | No | Clave secreta para la validación de firmas |
Formato de la URL del Webhook
Sección titulada «Formato de la URL del Webhook»POST https://your-domain.com/events/webhook/{tenant}/{event_type}Ejemplo:
POST https://your-domain.com/events/webhook/demo/order.createdManejo de Webhooks
Sección titulada «Manejo de Webhooks»Handler básico
Sección titulada «Handler básico»name: handle_webhookversion: "1.0"
nodes: - id: process type: script config: script: | let data = event.payload; // Process webhook data data next: respond
- id: respond type: http_response config: status: 200 body: success: true
triggers: - type: event event_type: "order.created" target: processWebhook de GitHub
Sección titulada «Webhook de GitHub»nodes: - id: check_event type: branch config: conditions: - expression: "headers['x-github-event'] == 'push'" next: handle_push - expression: "headers['x-github-event'] == 'pull_request'" next: handle_pr default: ignore
- id: handle_push type: script config: script: | let commits = event.payload.commits; format!("Received {} commits", commits.len())
triggers: - type: event event_type: "github" target: check_eventWebhook de Stripe
Sección titulada «Webhook de Stripe»nodes: - id: handle_stripe type: branch config: conditions: - expression: "event.payload.type == 'payment_intent.succeeded'" next: payment_success - expression: "event.payload.type == 'payment_intent.failed'" next: payment_failed
triggers: - type: event event_type: "stripe" target: handle_stripeValidación de firmas
Sección titulada «Validación de firmas»Validación HMAC
Sección titulada «Validación HMAC»{ "events-webhook": { "enabled": true, "public_base_url": "https://your-domain.com", "signatures": { "github": { "header": "X-Hub-Signature-256", "algorithm": "sha256", "secret": "your-github-secret" }, "stripe": { "header": "Stripe-Signature", "algorithm": "stripe", "secret": "whsec_xxx" } } }}Manejo de respuestas
Sección titulada «Manejo de respuestas»Respuesta inmediata
Sección titulada «Respuesta inmediata»La mayoría de los providers de webhook esperan una respuesta rápida:
- id: ack type: http_response config: status: 200 next: async_process # Process async after respondingProcesamiento asíncrono
Sección titulada «Procesamiento asíncrono»Para tareas de larga duración, confirma primero:
nodes: - id: acknowledge type: http_response config: status: 202 body: message: "Processing" next: process_async
- id: process_async type: async config: flow: "process_webhook_data" payload: "{{event.payload}}"Probar webhooks
Sección titulada «Probar webhooks»Usando curl
Sección titulada «Usando curl»curl -X POST https://your-domain.com/events/webhook/demo/test \ -H "Content-Type: application/json" \ -d '{"message": "Hello from webhook"}'Usando el inspector de ngrok
Sección titulada «Usando el inspector de ngrok»ngrok http 8080# Visit http://localhost:4040 to inspect requestsSolución de problemas
Sección titulada «Solución de problemas»Webhook no recibido
Sección titulada «Webhook no recibido»- Verifica que la URL sea correcta
- Comprueba que la URL pública sea accesible
- Revisa el firewall o los grupos de seguridad
- Consulta los logs del servicio externo
Falló la validación de firma
Sección titulada «Falló la validación de firma»- Verifica que la clave secreta coincida
- Comprueba que el nombre del header sea correcto
- Asegúrate de usar el cuerpo sin procesar para la validación