Skip to content

飞书:发消息工具支持富文本(粗体、链接、列表、代码) - #30

Merged
NginxL merged 9 commits into
mainfrom
feat/feishu-rich-send
Nov 26, 2026
Merged

NginxL merged 9 commits into
mainfrom
feat/feishu-rich-send

Conversation

@NginxL

@NginxL NginxL commented Nov 26, 2026

Copy link
Copy Markdown
Owner

做了什么

matefeishu_send、matefeishu_send_dm 的正文可以用 Markdown 的一个子集排版,发成飞书富文本(POST):

  • 支持:**粗体**、[文字](https://链接)、- / * / 1. 开头的列表(不嵌套)、`行内代码`、围栏代码块(可写语言)、# 标题(服务端会把标题降成段落,所以发成加粗的一行)、> 引用,空行分段、换行保留。
  • 一种格式都没用时,照旧按纯文本(TEXT)发,和以前一样。
  • 工具说明里写清了支持哪些写法(只在后端能发富文本时出现,微信不变)。

协议写法(按两个公开项目的实测结论,代码自己写的)

不变的行为

  • at 参数、正文里「@名字」变成真 @ 照旧;写在代码或链接里的「@名字」不算,那个人的 @ 放在最前面单独一行(纯文本还是放在最前面、空格隔开)。
  • 回复某条消息、发进话题、话题群、开了话题模式的群(5801 后用新客户端版本重发)都和发文字时同一条路,只是包的类型换成 POST。
  • /agent 回复、收件箱回复、自动代答不变,仍发纯文本。

其他

  • 手机确认卡:多一行「按飞书富文本发送:下面的粗体、链接…会按格式显示(这里是写的原文,链接的地址就是括号里的)」,下面是原文。
  • 渠道群里的回声:富文本读回来的文字和原文不同,发出前用「读回来会是什么」去认回声,避免被当成用户的话(测试群就是渠道群)。
  • 读取端认 MARKDOWN(49) 元素:机器人发的 Markdown post 以前读成空,现在读出原文。
  • 改了 core/,两个扩展都要升版本。

怎么验证的

  • bash scripts/test.sh(带 OPENMATE_LARKX_PYTHON,跑真 LarkAgentX 的离线 smoke 测试)全部通过。
  • 新增测试:tests/test_markup.py(解析、哪些算格式、@ 跳过代码和链接)、tests/test_actions.py::FormattedSendTest(工具说明、确认卡、rich 传到后端、纯文本不变、@)、tests/test_channel.py(回声按读回文字认)、test_larkagentx.py(富文本走和文字同样的位置:话题、引用、话题群、话题模式重发;@;构不成时一定不发)、test_smoke_larkx.py(真 protobuf:包的类型、元素树、样式表、atUserIdList,以及我们自己的读取端读回的文字和预计的一致)。新测试在旧代码上都会失败。

没做什么

  • 没做嵌套列表、斜体、删除线、表格、图片。
  • 微信(openmate-wechat)不改,只因 core 改动升版本。
  • 上线后在「OpenMate 测试」群里实测一条带格式的消息,并用 lark-cli 消息搜索核对格式和 @。

🤖 Generated with Claude Code

NginxL and others added 9 commits November 26, 2026 17:11
matefeishu_send and matefeishu_send_dm take **bold**, [words](https://address), "- " and "1. " lists,
`code` and fenced code blocks, "# " headings (a bold line) and "> " quotes, and send them as a POST whose rich
text is the web client's tree (DOCS over P / UL / OL / LI / QUOTE, bold as TEXT's fontWeight style, A links,
AT @s); code goes as a MARKDOWN element (the server flattens an inline CODE, the clients show a CODE_BLOCK
empty). A text without any of it goes as plain text, as before. at and "@name" in the words stay real @s
(none in code or a link: those go in front, on a line of their own); replies, threads and topics as before.
The card says it goes formatted and which formats; the 渠道's echo is known by the words it reads back as.
The reader reads a MARKDOWN element (a bot's Markdown post read as nothing before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…is no quote, Markdown made from the runs, indents and CRLF, unwritten @s a paragraph of their own, a formatted echo is no /agent request

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…id is known; link addresses and bare ones one piece, sentence marks after them not; names one piece; rules, titled images, tab fences, first-line indents, '1.5', '&'

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… the bare-address scan, image addresses and fullwidth letters kept; an @ in a bare address refused; rules in quotes and lists escaped; names never markup; a pending echo only a POST, none across accounts

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… mask; any case of scheme; a name masked wherever written; a formatted echo in the 渠道 known as a POST; a late end from the account before changes nothing

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ading only, every word and address written from the text; a link's address its own mask, lower-case http(s) only

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rom its own start; code fenced past its backticks; a mark written in the text is no mask

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…me's mask stays inside one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…the Markdown subset as Feishu rich text

matefeishu_send and matefeishu_send_dm send **bold**, [words](https://address), "- " and "1. " lists, `code`,
fenced code, "# " headings and "> " quotes as a POST (the web client's tree; code as MARKDOWN elements); a text
without any goes as plain text, as before. at and @name stay real @s; replies, threads and topics as before. The
card says it goes formatted. WeChat: only the core's bump. Codex rounds 1-7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@NginxL
NginxL force-pushed the feat/feishu-rich-send branch from 653663d to e399851 Compare November 26, 2026 09:18
@NginxL
NginxL merged commit e399851 into main Nov 26, 2026
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.

1 participant