Webhook
Webhook events provider 让你的数字员工能够接收来自 GitHub、Stripe、Shopify 等外部服务的 HTTP webhook。
-
配置 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}
| 选项 | 必填 | 说明 |
|---|---|---|
enabled | 是 | 启用/禁用 provider |
public_base_url | 是 | webhook 的公网 URL |
secret_header | 否 | 用于签名校验的 header 名称 |
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.created处理 Webhook
Section titled “处理 Webhook”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" } } }}大多数 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未收到 Webhook
Section titled “未收到 Webhook”- 检查 URL 是否正确
- 确认公网 URL 可访问
- 检查防火墙/安全组
- 查看外部服务日志
签名校验失败
Section titled “签名校验失败”- 确认密钥一致
- 检查 header 名称是否正确
- 确保校验时使用原始请求体