Skip to content

fix(channel): detect @all in rich-text post messages (fixes #138) - #152

Open
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/channel-post-mention-all
Open

fix(channel): detect @all in rich-text post messages (fixes #138)#152
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/channel-post-mention-all

Conversation

@Xuxchloris

Copy link
Copy Markdown

Fixes #138

Problem

For post (rich-text) messages that mention everyone, InboundMessage.mentioned_all is always False, so PolicyGate never emits policy_mention_all_blocked and a bot configured with respond_to_mention_all=False still responds to broadcast @all posts. Plain-text @all messages are handled correctly.

Two compounding issues in the post inbound path:

  1. Feishu does not populate mentions[] for post @all — the signal lives in the post AST as an at node with user_id == "all". _flatten_post_text rendered that node to the literal @<user_name> (@Everyone), which neither text_has_mention_all (looks for the @_all placeholder) nor parse_at_tags (looks for <at> tags) can match.
  2. _flatten_post_text only handled locale-keyed post payloads ({"zh_cn": ...}); the classic single-locale shape {"content": ...} (the one used in the issue reproduction) returned an empty text, so the probe never even ran.

Changes

  • lark_oapi/channel/normalize/registry.py
    • _flatten_post_text now accepts both wire shapes: locale-keyed posts and the direct {"content": ...} shape.
    • An at node whose user_id == "all" (top-level or inside id) renders as the @_all placeholder, so the pipeline's text_has_mention_all probe fires and resolve_mentions rewrites it to the human-visible @all.
  • lark_oapi/channel/tests/test_post_mention_all.py (new): pipeline-level tests for both post shapes (@allmentioned_all=True, rendered @all; a regular @<user> mention → mentioned_all=False, name rendered).

Verification

  • python -m pytest lark_oapi/channel/tests — 662 passed; the single failure (test_upload_error_propagation.py::test_gather_buffer_missing_local_file_raises_upload_failed) is a pre-existing Windows-only path-escaping assertion unrelated to this change (CI runs on Linux).

@CLAassistant

CLAassistant commented Aug 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@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.
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.

[Python lark-oapi 1.6.9] InboundMessage.mentioned_all is always False for post (rich-text) @all messages

2 participants