Skip to content

API 参考: 事件 (Events)

事件订阅与 Webhook 管理端点。

注册 Webhook 订阅

订阅指定事件,当事件发生时平台向目标 URL 发送 POST 请求。

POST /v1/events/webhooks

权限要求: write

请求体

字段类型必填说明
eventstring事件类型(见下方列表)
urlstringWebhook 接收地址
secretstring用于 HMAC-SHA256 签名验证的密钥
filterobject过滤条件,仅投递匹配的事件

可用事件类型

事件说明
app.installed应用安装
app.configured应用配置完成
tool.executed工具执行成功
tool.failed工具执行失败
knowledge.updated知识库更新
graph.synced图谱同步完成
workflow.completed工作流执行成功
workflow.failed工作流执行失败
alert.triggered报警触发
ai.conversationAI 对话完成

请求示例

bash
curl -X POST https://api.invoratec.cn/v1/events/webhooks \
  -H "X-API-Key: claw_xxxx" \
  -H "Content-Type: application/json" \
  -d '{
    "event": "workflow.completed",
    "url": "https://my-server.com/webhooks/workflow",
    "secret": "my-webhook-secret",
    "filter": {}
  }'

响应 (201 Created)

json
{
  "id": "665f1a2b3c4d5e6f7a8b9c0d",
  "developerId": "user_123",
  "event": "workflow.completed",
  "url": "https://my-server.com/webhooks/workflow",
  "filter": {},
  "enabled": true,
  "createdAt": "2026-04-12T08:00:00.000Z",
  "lastTriggered": null,
  "failCount": 0
}

错误

状态码说明
400eventurl 缺失,或事件类型无效
403缺少 write 权限

列出 Webhook 订阅

GET /v1/events/webhooks

请求示例

bash
curl https://api.invoratec.cn/v1/events/webhooks \
  -H "X-API-Key: claw_xxxx"

响应

json
{
  "webhooks": [
    {
      "_id": "665f...",
      "event": "workflow.completed",
      "url": "https://my-server.com/webhooks/workflow",
      "enabled": true,
      "lastTriggered": "2026-04-12T09:00:00.000Z",
      "failCount": 0,
      "createdAt": "2026-04-12T08:00:00.000Z"
    }
  ],
  "eventTypes": [
    "app.installed", "app.configured",
    "tool.executed", "tool.failed",
    "knowledge.updated", "graph.synced",
    "workflow.completed", "workflow.failed",
    "alert.triggered", "ai.conversation"
  ]
}

响应中同时返回 eventTypes 列表,方便客户端展示可选事件。


删除 Webhook 订阅

DELETE /v1/events/webhooks/{id}

路径参数

参数类型说明
idstringWebhook _id

请求示例

bash
curl -X DELETE https://api.invoratec.cn/v1/events/webhooks/665f... \
  -H "X-API-Key: claw_xxxx"

响应

json
{ "success": true }

列出事件类型

获取所有可订阅的事件类型列表。

GET /v1/events/types

请求示例

bash
curl https://api.invoratec.cn/v1/events/types \
  -H "X-API-Key: claw_xxxx"

响应

json
{
  "eventTypes": [
    "app.installed",
    "app.configured",
    "tool.executed",
    "tool.failed",
    "knowledge.updated",
    "graph.synced",
    "workflow.completed",
    "workflow.failed",
    "alert.triggered",
    "ai.conversation"
  ]
}

查看事件日志

获取 API 调用日志记录,按时间倒序排列。

GET /v1/events/logs

查询参数

参数类型说明
limitinteger返回上限,默认 100

请求示例

bash
curl "https://api.invoratec.cn/v1/events/logs?limit=50" \
  -H "X-API-Key: claw_xxxx"

响应

json
{
  "logs": [
    {
      "_id": "665f...",
      "userId": "user_123",
      "endpoint": "/v1/ai/chat",
      "method": "POST",
      "status": 200,
      "timestamp": "2026-04-12T09:00:00.000Z",
      "responseTime": 1500
    },
    {
      "_id": "665e...",
      "userId": "user_123",
      "endpoint": "/v1/tools/erp_get_inventory/test",
      "method": "POST",
      "status": 200,
      "timestamp": "2026-04-12T08:30:00.000Z",
      "responseTime": 230
    }
  ]
}

Webhook 投递格式

当事件触发时,平台向订阅的 URL 发送如下格式的 POST 请求:

请求头

Content-Type: application/json
X-Webhook-Event: tool.executed
X-Webhook-Timestamp: 2026-04-12T08:00:00.000Z
X-Webhook-Signature: sha256=abc123def456...

X-Webhook-Signature 仅在注册时设置了 secret 时才会出现。签名算法为 HMAC-SHA256,签名内容为请求体的原始 JSON 字符串。

请求体

json
{
  "event": "tool.executed",
  "timestamp": "2026-04-12T08:00:00.000Z",
  "data": {
    "toolName": "erp_get_inventory",
    "input": { "warehouse_id": "WH-001" },
    "result": { "items": [...], "total": 42 },
    "elapsed_ms": 230
  }
}

各事件的 data 字段

事件data 内容
tool.executedtoolName, input, result, elapsed_ms
tool.failedtoolName, input, error
workflow.completedworkflowId, workflowName, runId, status, stepResults
workflow.failedworkflowId, workflowName, runId, error
knowledge.updatedknowledgeId, action (upload/update), documentTitle
graph.syncedgraphId, nodesWritten, edgesWritten
alert.triggeredalertType, source, message, severity
ai.conversationmodel, inputTokens, outputTokens
app.installedappId, appName
app.configuredappId, appName

签名验证

python
import hmac, hashlib

def verify(body: bytes, signature: str, secret: str) -> bool:
    expected = hmac.new(secret.encode(), body, hashlib.sha256).hexdigest()
    return hmac.compare_digest(f"sha256={expected}", signature)
javascript
const crypto = require('crypto')

function verify(body, signature, secret) {
  const expected = crypto.createHmac('sha256', secret).update(body).digest('hex')
  return signature === `sha256=${expected}`
}

智航云 AI 中台 — 开发者平台