Skip to content

Feat/cross bot mention#358

Open
Maschera96 wants to merge 3 commits into
larksuite:mainfrom
Maschera96:feat/cross-bot-mention
Open

Feat/cross bot mention#358
Maschera96 wants to merge 3 commits into
larksuite:mainfrom
Maschera96:feat/cross-bot-mention

Conversation

@Maschera96
Copy link
Copy Markdown

Summary

实现跨 Bot @提及功能,允许同一插件实例中的 Bot A 在消息中 @提及 Bot B,从而触发 Bot B 的消息处理流程。

飞书平台存在限制:Bot 无法看到其他 Bot 发送的消息。本 PR 通过合成消息事件(synthetic message event)的方式绕过此限制——当 Bot A 发送包含 @bot B 的消息时,在本地直接调用 Bot B 的
im.message.receive_v1 处理器。

核心变更:

  • 新增 src/messaging/cross-bot/ 模块,包含跨 Bot 触发逻辑与合成消息事件构造
  • LarkClient 新增静态注册表,用于跨 Bot 间共享 Bot open_id、名称及 WebSocket handlers
  • sendMessageFeishu 在发送后检测 @mentions 中是否包含其他 Bot,异步触发跨 Bot 消息
  • reply-dispatcher 提取文本中的 标签为 MentionInfo[],传递至发送层
  • 新增 feishu_list_bots 工具,供 AI 发现可用 Bot 以生成正确的 @mention
  • 事件所有权校验跳过 synthetic_om_ 前缀的合成消息

新增/修改文件(11 个,+479/-21):

┌────────────────────────────────────┬───────────────────────────────────────────────────┐
│ 文件 │ 说明 │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ src/messaging/cross-bot/trigger.ts │ 跨 Bot 触发核心逻辑 │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ src/messaging/cross-bot/index.ts │ 模块导出 │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ src/messaging/inbound/mention.ts │ 新增 extractAtMentionsFromText 解析内联 标签 │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ src/messaging/outbound/send.ts │ 发送后检测并触发跨 Bot 消息 │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ src/core/lark-client.ts │ Bot 注册表(open_id / name / handlers) │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ src/card/reply-dispatcher.ts │ 提取 mentions 并传递给发送函数 │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ src/channel/monitor.ts │ 注册 handlers 到 LarkClient │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ src/channel/event-handlers.ts │ 合成消息跳过 app_id 校验 │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ src/tools/list-bots.ts │ 新工具:列出所有已注册 Bot │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ index.ts │ 注册 feishu_list_bots 工具 │
├────────────────────────────────────┼───────────────────────────────────────────────────┤
│ package.json │ 新增 dev script(tsdown --watch) │
└────────────────────────────────────┴───────────────────────────────────────────────────┘

Test plan

  • 部署多个 Bot 实例,验证 Bot A @bot B 后 Bot B 能正常响应
  • 验证 AI 调用 feishu_list_bots 能正确返回所有 Bot 信息
  • 验证自提及(Bot @自己)被正确跳过
  • 验证合成消息不干扰正常消息处理流程
  • 验证跨 Bot 触发失败不影响原始消息发送

Naois and others added 3 commits March 30, 2026 18:54
- reply-dispatcher 中提取文本内联 <at> 标签为 MentionInfo 传给 sendMessageFeishu
- sendMessageFeishu 跳过已在文本中的 mentions 避免重复追加
- cross-bot trigger 使用真实飞书消息 ID 替代合成 ID,修复 API 400 错误
- 修复合成事件 mentions 指向目标 bot(非发送者 bot)
- 修复 create_time 时间戳单位(秒→毫秒),避免消息被判定为过期
- 添加 dev watch 模式脚本

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Naois seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants