feat(channel): render post attachment zone in normalize - #20
Merged
mazhe-nerd merged 2 commits intoAug 31, 2026
Merged
Conversation
The rich-text attachment zone (top-level files array) was ignored by the post converter: only the locale document (title/content/content_v2) was flattened and scanned for resources, so attachments attached to a rich-text message were invisible to channel consumers. - render attachment-zone files as <file key=... name=.../> lines and is_folder entries as <folder .../> lines, matching the standalone file/folder converters - surface attachment-zone files as ResourceDescriptor(type=file) so they are downloadable; folders remain tag-only like the folder converter - include the attachment zone in convert_body (InboundMessage.body_text) - cover with tests: rendering + resource extraction, empty files array, body_text propagation
yjhcjykwbk-jlsec
force-pushed
the
feat/post-attachment-zone
branch
from
August 31, 2026 09:30
7ca71ba to
ca713f1
Compare
Maintainer follow-up on the attachment-zone support in this branch.
- Read the attachment zone before the no-locale-document guard. A post
carrying only attachments previously returned empty text while still
surfacing downloadable resources, so the two paths disagreed on the
same input.
- Narrow every attachment field at extraction time. A non-string
file_name would otherwise reach attr() and raise out of the normalize
pipeline, which has no converter-level trap; a stringly is_folder
("false") would hide a real, downloadable file behind a <folder/> tag.
- Escape the key as well as the name, so neither field can close the
attribute and forge a sibling tag.
- Pick the first dict-valued entry as the locale document in
_flatten_post_text. The wire may place `files` before the locale key,
which emptied PostContent.text and with it the pipeline's @ALL probe
and <at>-tag parsing.
- Collapse the file/folder render matrix into _render_attachment.
Covered by seven new tests. Bump to 1.4.0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The rich-text attachment zone (top-level
filesarray on a post message) was ignored by the post converter: only the locale document (title/content/content_v2) was flattened and scanned for resources, so attachments attached to a rich-text message were invisible to channel consumers.This PR makes the attachment zone visible and downloadable (node-aligned with larksuite/channel-sdk-node):
lark_channel/channel/normalize/converters/post.py_attachment_files(): extract the top-levelfiles: [{file_key, file_name, is_folder}]array<file key="..." name="..."/>/<folder key="..." name="..."/>lines after the body, matching the standalone file/folder convertersResourceDescriptor(type="file")so they are downloadable; folders stay tag-only (mirrors the standalone folder converter'sresources=[])convert_body(i.e.InboundMessage.body_text)lark_channel/channel/tests/test_flatten.py: three new tests — rendering + resource extraction, emptyfilesarray tolerance, andbody_textpropagationWire shape
{ "zh_cn": { "title": "报告", "content": [[{"tag": "text", "text": "正文"}]] }, "files": [ { "file_key": "file_a", "file_name": "report.pdf" }, { "file_key": "dir_1", "file_name": "assets", "is_folder": true } ] }renders as:
with
resources: [ResourceDescriptor(type="file", file_key="file_a", file_name="report.pdf")].Test