🪝 Webhook Integration(Webhook集成)

不是你去找信息,而是信息来找你——Webhook 就是那个"送货上门"的机制。

📖 什么是 Webhook Integration?

Webhook Integration 是一种事件驱动的通信模式,允许外部系统在特定事件发生时主动向 OpenClaw Agent 推送通知。与轮询(Polling)不同,Webhook 是实时的、被动的——有事才叫你。

⚡ Webhook vs Polling

特性WebhookPolling
实时性✅ 实时推送❌ 有延迟
资源消耗✅ 低(有事件才触发)❌ 高(持续轮询)
实现复杂度中等简单
适用场景事件驱动状态检查

🔧 OpenClaw 中的 Webhook 配置

// Cron 任务的 Webhook 投递配置
{
  "delivery": {
    "mode": "webhook",
    "to": "https://your-server.com/webhook"
  }
}

// 完整的 Cron Job 配置
{
  "name": "daily-report-webhook",
  "schedule": { "kind": "cron", "expr": "0 8 * * *" },
  "payload": { "kind": "agentTurn", "message": "生成日报" },
  "delivery": {
    "mode": "webhook",
    "to": "https://api.example.com/report"
  }
}

🏗️ Webhook 工作流程

外部系统                    OpenClaw Gateway
   │                              │
   │  1. 事件发生                 │
   │  ─────────────────────────►  │
   │  POST /webhook               │
   │  {event: "data"}             │
   │                              │
   │  2. Gateway 处理事件         │
   │     → 触发 Agent             │
   │     → 执行任务               │
   │                              │
   │  3. 返回结果                 │
   │  ◄─────────────────────────  │
   │  200 OK {result: "..."}      │

💡 常见应用场景

1. GitHub Webhook

当 GitHub 仓库有新的 PR、Issue 或 Push 时,自动通知 Agent 处理。

2. 飞书/钉钉事件回调

接收消息、审批、日程等事件,自动触发 Agent 响应。

3. CI/CD 流水线

构建完成、部署成功等事件触发 Agent 发送通知或执行后续任务。

🔗 相关推荐