Webhook
Ringkasan
Section titled “Ringkasan”Provider event Webhook memungkinkan digital worker Anda menerima webhook HTTP dari layanan eksternal seperti GitHub, Stripe, Shopify, dan sebagainya.
Penyiapan
Section titled “Penyiapan”-
Konfigurasikan Provider
answers.json {"events-webhook": {"enabled": true,"public_base_url": "https://your-domain.ngrok-free.app"}} -
Jalankan Setup
Terminal window gtc setup --answers answers.json ./my-bundle -
Daftarkan Webhook
Gunakan URL webhook yang dihasilkan di layanan eksternal Anda:
https://your-domain.com/events/webhook/{tenant}/{event_type}
Opsi Konfigurasi
Section titled “Opsi Konfigurasi”| Opsi | Wajib | Deskripsi |
|---|---|---|
enabled | Ya | Aktifkan/nonaktifkan provider |
public_base_url | Ya | URL publik untuk webhook |
secret_header | Tidak | Nama header untuk validasi signature |
secret_key | Tidak | Secret key untuk validasi signature |
Format URL Webhook
Section titled “Format URL Webhook”POST https://your-domain.com/events/webhook/{tenant}/{event_type}Contoh:
POST https://your-domain.com/events/webhook/demo/order.createdMenangani Webhook
Section titled “Menangani Webhook”Handler Dasar
Section titled “Handler Dasar”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 GitHub
Section titled “Webhook 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 Stripe
Section titled “Webhook 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_stripeValidasi Signature
Section titled “Validasi Signature”Validasi HMAC
Section titled “Validasi 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" } } }}Penanganan Respons
Section titled “Penanganan Respons”Respons Langsung
Section titled “Respons Langsung”Sebagian besar provider webhook mengharapkan respons cepat:
- id: ack type: http_response config: status: 200 next: async_process # Process async after respondingPemrosesan Async
Section titled “Pemrosesan Async”Untuk tugas yang berjalan lama, kirim acknowledgment terlebih dahulu:
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}}"Menguji Webhook
Section titled “Menguji Webhook”Menggunakan curl
Section titled “Menggunakan curl”curl -X POST https://your-domain.com/events/webhook/demo/test \ -H "Content-Type: application/json" \ -d '{"message": "Hello from webhook"}'Menggunakan inspector ngrok
Section titled “Menggunakan inspector ngrok”ngrok http 8080# Visit http://localhost:4040 to inspect requestsTroubleshooting
Section titled “Troubleshooting”Webhook Tidak Diterima
Section titled “Webhook Tidak Diterima”- Periksa apakah URL sudah benar
- Pastikan URL publik dapat diakses
- Periksa firewall/security group
- Tinjau log layanan eksternal
Validasi Signature Gagal
Section titled “Validasi Signature Gagal”- Pastikan secret key sesuai
- Periksa apakah nama header benar
- Pastikan body mentah digunakan untuk validasi