Webhook
Überblick
Abschnitt betitelt „Überblick“Der Webhook-Events-Provider ermöglicht es Ihrem digitalen Worker, HTTP-Webhooks von externen Diensten wie GitHub, Stripe, Shopify usw. zu empfangen.
Einrichtung
Abschnitt betitelt „Einrichtung“-
Provider konfigurieren
answers.json {"events-webhook": {"enabled": true,"public_base_url": "https://your-domain.ngrok-free.app"}} -
Setup ausführen
Terminal-Fenster gtc setup --answers answers.json ./my-bundle -
Webhook registrieren
Verwenden Sie die generierte Webhook-URL in Ihrem externen Dienst:
https://your-domain.com/events/webhook/{tenant}/{event_type}
Konfigurationsoptionen
Abschnitt betitelt „Konfigurationsoptionen“| Option | Erforderlich | Beschreibung |
|---|---|---|
enabled | Ja | Provider aktivieren/deaktivieren |
public_base_url | Ja | Öffentliche URL für Webhooks |
secret_header | Nein | Header-Name für die Signaturvalidierung |
secret_key | Nein | Geheimer Schlüssel für die Signaturvalidierung |
Webhook-URL-Format
Abschnitt betitelt „Webhook-URL-Format“POST https://your-domain.com/events/webhook/{tenant}/{event_type}Beispiel:
POST https://your-domain.com/events/webhook/demo/order.createdWebhooks verarbeiten
Abschnitt betitelt „Webhooks verarbeiten“Einfacher Handler
Abschnitt betitelt „Einfacher Handler“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: processGitHub-Webhook
Abschnitt betitelt „GitHub-Webhook“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_eventStripe-Webhook
Abschnitt betitelt „Stripe-Webhook“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_stripeSignaturvalidierung
Abschnitt betitelt „Signaturvalidierung“HMAC-Validierung
Abschnitt betitelt „HMAC-Validierung“{ "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" } } }}Antwortverarbeitung
Abschnitt betitelt „Antwortverarbeitung“Sofortige Antwort
Abschnitt betitelt „Sofortige Antwort“Die meisten Webhook-Provider erwarten eine schnelle Antwort:
- id: ack type: http_response config: status: 200 next: async_process # Process async after respondingAsynchrone Verarbeitung
Abschnitt betitelt „Asynchrone Verarbeitung“Bestätigen Sie bei langlaufenden Aufgaben zuerst den Empfang:
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}}"Webhooks testen
Abschnitt betitelt „Webhooks testen“Mit curl
Abschnitt betitelt „Mit curl“curl -X POST https://your-domain.com/events/webhook/demo/test \ -H "Content-Type: application/json" \ -d '{"message": "Hello from webhook"}'Mit dem ngrok-Inspector
Abschnitt betitelt „Mit dem ngrok-Inspector“ngrok http 8080# Visit http://localhost:4040 to inspect requestsFehlerbehebung
Abschnitt betitelt „Fehlerbehebung“Webhook nicht empfangen
Abschnitt betitelt „Webhook nicht empfangen“- Prüfen Sie, ob die URL korrekt ist
- Stellen Sie sicher, dass die öffentliche URL erreichbar ist
- Prüfen Sie Firewall-/Security-Group-Einstellungen
- Sehen Sie die Logs des externen Dienstes durch
Signaturvalidierung fehlgeschlagen
Abschnitt betitelt „Signaturvalidierung fehlgeschlagen“- Prüfen Sie, ob der geheime Schlüssel übereinstimmt
- Prüfen Sie, ob der Header-Name korrekt ist
- Stellen Sie sicher, dass für die Validierung der rohe Request-Body verwendet wird