首页 资讯 下载 教程 Skills 社群

OpenClaw Webhook TaskFlow 配置教程:HTTP 触发 Agent 工作流

什么是 Webhook TaskFlow

Webhook TaskFlow 是 OpenClaw v2026.4.7 新增的功能,允许外部系统通过 HTTP 请求触发 Agent 工作流。这是 OpenClaw 从"对话工具"迈向"生产级自动化平台"的关键能力。

工作原理:

  1. OpenClaw 暴露一个 HTTP 端点
  2. 外部系统 POST 到该端点并携带 payload
  3. OpenClaw 验证请求(token 鉴权)
  4. 执行预定义的 TaskFlow 工作流图

前置要求

  • OpenClaw v2026.4.7 或更高版本
  • 对公网可访问的网关地址(或使用 Tailscale/Cloudflare Tunnel 暴露本地服务)

基础配置

Webhook 配置在 OpenClaw 配置文件的 hooks 块下。

# config.yaml
hooks:
  webhooks:
    enabled: true
    port: 18790
    endpoints:
      - path: "/taskflow/deploy"
        token: "your-secret-token"
        flow: "deploy-workflow"

配置说明:

字段 说明
enabled 是否启用 Webhook 系统
port Webhook 监听端口
path 端点路径
token 鉴权 Token
flow 要触发的 TaskFlow 名称

定义工作流

workflows/deploy-workflow.yaml 中定义具体流程:

name: deploy-workflow
trigger: webhook
steps:
  - id: notify
    tool: message
    args:
      channel: "feishu:dev"
      text: "收到部署请求,开始处理..."

  - id: pull
    command: "git pull origin main"

  - id: test
    command: "npm test"

  - id: deploy
    command: "pm2 restart app"
    when: $test.success

  - id: report
    tool: message
    args:
      channel: "feishu:dev"
      text: "部署${deploy.success ? '成功' : '失败'}"

触发方式

使用 curl

curl -X POST https://your-gateway.example.com/taskflow/deploy \
  -H "Content-Type: application/json" \
  -H "X-OpenClaw-Token: your-secret-token" \
  -d '{"branch": "main", "commit": "abc123"}'

GitHub Actions 集成

# .github/workflows/deploy.yml
- name: Trigger OpenClaw Deploy
  run: |
    curl -X POST https://your-gateway.example.com/taskflow/deploy \
      -H "X-OpenClaw-Token: $" \
      -d '{"ref": "$", "sha": "$"}'

钉钉机器人告警

# 钉钉告警 webhook 触发
hooks:
  webhooks:
    endpoints:
      - path: "/taskflow/alert"
        token: "alert-token"
        flow: "incident-response"

钉钉配置告警时 webhook 地址填写 OpenClaw 端点,Agent 收到告警后自动诊断和响应。

典型应用场景

1. CI/CD 自动部署

name: ci-deploy
steps:
  - command: "git pull && npm install"
  - command: "npm test"
  - command: "npm run build"
  - command: "pm2 restart all"
  - tool: message
    args:
      channel: "feishu:ops"
      text: "部署完成: $ci-deploy.result"

2. 工单自动分类

表单系统提交后触发 Webhook,Agent 分析工单内容并自动分配:

name: ticket-triage
steps:
  - id: classify
    tool: llm-task
    args:
      prompt: "分类工单:bug/feature/question"
      input: $webhook.body

  - id: assign
    tool: message
    args:
      channel: "feishu:${classify.category}-team"
      text: "新工单: ${webhook.body.title}"

3. 监控告警自动诊断

Prometheus 或 Grafana 告警触发 Webhook,Agent 自动收集诊断信息:

name: alert-diagnosis
steps:
  - command: "kubectl get pods -A | grep -v Running"
  - command: "dmesg | tail -50"
  - tool: llm-task
    args:
      prompt: "分析以下诊断信息,给出初步判断"
      input: $step1.stdout

安全最佳实践

Token 鉴权

务必为每个 endpoint 设置独立的强 token:

endpoints:
  - path: "/taskflow/deploy"
    token: "$(openssl rand -hex 32)"  # 使用强随机 token

IP 白名单

限制可访问 webhook 的 IP:

hooks:
  webhooks:
    allowedIps:
      - "192.168.1.0/24"  # 内网
      - "140.82.114.0/24"  # GitHub Actions

使用内网穿透

对于开发环境,推荐使用 Tailscale 或 Cloudflare Tunnel,避免直接暴露公网:

# Tailscale
openclaw gateway --tailscale

# Cloudflare Tunnel
cloudflared tunnel --url http://localhost:18790

调试技巧

查看 Webhook 日志

openclaw logs --filter webhook --follow

本地测试

# 模拟 webhook 触发
curl -X POST http://localhost:18790/taskflow/deploy \
  -H "X-OpenClaw-Token: test-token" \
  -d '{"test": true}'

查看 TaskFlow 状态

openclaw tasks flow list
openclaw tasks flow show <flow-id>

注意事项

  • Webhook 端口务必通过防火墙控制访问
  • 高频 webhook 建议加入速率限制防止 DoS
  • 敏感操作(生产部署等)建议配合 Lobster 工作流的审批门控
  • Token 应存储在环境变量或 Secrets Management,不要明文写在配置里
  • 需要 OpenClaw v2026.4.7 或更高版本