跳转到内容

事件模型

MessageEvent 是系统的核心数据结构,所有输入渠道的消息都会统一转化为此模型:

interface MessageEvent {
event_id: string;
trace_id?: string;
owner_user_id: string;
source: string;
source_event_id?: string;
actor?: Actor;
context?: EventContext;
type: EventType;
payload: EventPayload;
entities: Entity[];
ts: string;
dedupe_key: string;
visibility: "private" | "team" | "public";
status: "pending" | "processed" | "failed";
bind_id?: string;
created_at?: string;
updated_at?: string;
}

当前内置 source 包括 wechat_mp、weixin、feishu、telegram、discord、slack、x、api、app_share、email。source 是开放字符串,不限于以上取值。

EventType 当前包括:

type EventType =
| "message.text"
| "message.link"
| "message.image"
| "message.file"
| "message.voice"
| "message.video"
| "message.rich"
| "reaction.add"
| "mention"
| "bookmark"
| "share";

事件的 payload.raw 始终存在,保存渠道的原始 payload。

同一账号下,dedupe_key 相同的事件只保留一条:

  • 通过 POST /v1/events 上报时可以显式传入 dedupe_key;不传时按 source_event_id 生成。因此用相同的 source_event_id 重复上报会返回 created: false(HTTP 200),不会生成新事件。
  • 通过渠道 Webhook 进入的事件,由 MessageRouter 根据平台事件特征去重。