跳转到内容

路由规则配置

事件被接收后,MessageRouter 在后台按优先级(priority 从高到低)将事件与你已启用的路由规则逐条匹配,命中的规则按顺序执行其 actions。每次执行的结果都会记录下来,可以在 Dashboard「执行日志」或通过 GET /v1/route-logs 查看。

可以在 Dashboard「路由规则」页面创建,也可以调用 POST /v1/routes,请求体示例:

{
"name": "链接通知",
"priority": 10,
"mode": "fanout",
"match": {
"source": ["feishu"],
"type": ["message.link"]
},
"actions": [
{
"type": "notify",
"bind_id": "bind_01JD8...",
"config": {
"template": "📌 {{payload.title}}\n{{payload.url}}"
}
}
]
}

mode 默认为 fanout,会执行所有命中的规则。设置为 first-match 后,路由引擎会在命中该规则时停止执行更低优先级的规则。

interface MatchConfig {
source?: string[];
type?: string[];
keyword?: string[]; // 匹配 payload.text / payload.title
regex?: string; // 匹配 payload.text
url_domain?: string[];
actor_user_id?: string[];
channel_id?: string[];
visibility?: string[];
time_window?: {
days?: number[];
hours_start?: number;
hours_end?: number;
timezone?: string;
};
}

条件之间是 AND 关系;同一字段内多个值是 OR 关系。

interface ActionConfig {
type: "store" | "notify" | "agent" | "transform" | "moderate" | "http";
bind_id?: string;
config?: Record<string, unknown>;
}

notify 可以通过 bind_id 发送到支持出站发送的渠道(wechat_mp、email、feishu、telegram、discord、slack、weixin),也可以通过 config.webhook_url 直接调用 Webhook。config.template 中可以使用 {{payload.title}}、{{payload.url}} 等事件字段。

{
"type": "notify",
"bind_id": "bind_feishu",
"config": {
"template": "📌 {{payload.title}}\n{{payload.url}}"
}
}

http action 需要 bind_id;对应 ConnectorBind 的 config.base_url 是请求基址。

{
"type": "http",
"bind_id": "bind_http",
"config": {
"path": "/messages",
"method": "POST",
"body": {
"text": "{{payload.text}}"
}
}
}

这些 action 不需要 bind_id:

  • agent: 为事件生成摘要和标签,见 Agent 集成
  • transform: 做 URL/文本等转换
  • moderate: 当前为占位审核, 恒返回 allow, 不执行实际内容检查
  • store: 当前保留该类型,不执行实际写入
{
"name": "工作时间消息转发",
"priority": 5,
"match": {
"keyword": ["紧急", "urgent"],
"time_window": {
"days": [1, 2, 3, 4, 5],
"hours_start": 9,
"hours_end": 18
}
},
"actions": [
{
"type": "notify",
"bind_id": "bind_feishu",
"config": {
"template": "🚨 紧急消息: {{payload.text}}"
}
}
]
}