Webhook
Webhook events provider を使うと、digital worker は GitHub、Stripe、Shopify などの外部サービスから HTTP webhook を受信できます。
セットアップ
Section titled “セットアップ”-
provider を設定する
answers.json {"events-webhook": {"enabled": true,"public_base_url": "https://your-domain.ngrok-free.app"}} -
セットアップを実行する
Terminal window gtc setup --answers answers.json ./my-bundle -
Webhook を登録する
外部サービスで、生成された webhook URL を使用します:
https://your-domain.com/events/webhook/{tenant}/{event_type}
設定オプション
Section titled “設定オプション”| Option | Required | Description |
|---|---|---|
enabled | Yes | provider を有効/無効にする |
public_base_url | Yes | webhook 用の公開 URL |
secret_header | No | 署名検証に使う header 名 |
secret_key | No | 署名検証に使う secret key |
Webhook URL 形式
Section titled “Webhook URL 形式”POST https://your-domain.com/events/webhook/{tenant}/{event_type}例:
POST https://your-domain.com/events/webhook/demo/order.createdWebhook の処理
Section titled “Webhook の処理”基本ハンドラー
Section titled “基本ハンドラー”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
Section titled “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
Section titled “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_stripeHMAC 検証
Section titled “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" } } }}レスポンス処理
Section titled “レスポンス処理”即時レスポンス
Section titled “即時レスポンス”多くの webhook provider は素早いレスポンスを期待します:
- id: ack type: http_response config: status: 200 next: async_process # Process async after responding長時間かかる処理では、先に受領応答を返します:
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}}"Webhook のテスト
Section titled “Webhook のテスト”curl を使う
Section titled “curl を使う”curl -X POST https://your-domain.com/events/webhook/demo/test \ -H "Content-Type: application/json" \ -d '{"message": "Hello from webhook"}'ngrok inspector を使う
Section titled “ngrok inspector を使う”ngrok http 8080# Visit http://localhost:4040 to inspect requestsトラブルシューティング
Section titled “トラブルシューティング”Webhook を受信できない
Section titled “Webhook を受信できない”- URL が正しいことを確認する
- 公開 URL にアクセスできることを確認する
- firewall / security group を確認する
- 外部サービスの log を確認する
署名検証に失敗する
Section titled “署名検証に失敗する”- secret key が一致していることを確認する
- header 名が正しいことを確認する
- 検証に raw body を使っていることを確認する