Skip to content

队列事件与 IM 字段对齐(契约)

目的:双栈(IM 与队列机器人)并存时,同一语义使用相同或显式映射的字段名,避免 Agent 与文档各写一套键。

IM 侧权威类型(@zhin.js/core

入站 Message(节选)

packages/core/src/message.tsMessageBase

字段含义
$adapter适配器名( keyof Adapters )
$botBot 实例标识
$channel.id / $channel.type会话 id、group | private | channel
$senderMessageSenderid、可选 name / role
$content / $raw结构化内容 / 纯文本
$reply(content)推荐出站 API(走 Adapter 链)

出站 SendOptionstypes.ts

字段含义
context适配器上下文名(与 $adapter 同源语义)
botBot 名
id目标会话或用户 id(与 $channel.id 对齐)
typeMessageType,与 $channel.type 对齐
contentSendContent

出站润色

字段含义
OutboundReplySource'command' | 'ai'(仅 replyWithPolish 路径带 AsyncLocalStorage)

队列侧(约定 / 占位)

当引入 qbot / 双队列 时,建议在事件 detail 或 job payload 中显式携带:

语义建议键名对应 IM
适配器/上下文contextadapter(二选一,全仓库统一SendOptions.context / Message.$adapter
BotbotSendOptions.bot / Message.$bot
目标 idchannelIdid统一SendOptions.id
频道类型channelTypetype统一SendOptions.type
发送者senderIdMessage.$sender.id
正文contenttext统一SendOptions.content / Message.$raw

规则:新代码禁止混用 sceneId/roomId/peerId 等不与上表映射表对照的裸键;若平台必须用异名,在适配层做 一次性 映射并文档化。

相关

基于 MIT 许可发布