Skip to content

fix(channel): populate InboundMessage.mentioned_bot from mentions (fixes #134) - #151

Open
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/channel-mentioned-bot
Open

fix(channel): populate InboundMessage.mentioned_bot from mentions (fixes #134)#151
Xuxchloris wants to merge 1 commit into
larksuite:v2_mainfrom
Xuxchloris:fix/channel-mentioned-bot

Conversation

@Xuxchloris

Copy link
Copy Markdown

Fixes #134

Problem

InboundMessage.mentioned_bot is unconditionally False for every IM message, even when the bot is explicitly mentioned and the bot identity is resolved. Two compounding omissions in lark_oapi/channel/normalize/pipeline.py:

  1. extract_mentions(raw_mentions) never receives bot_open_id, so mentions.py can never flag the bot self-mention.
  2. Even when computed, ext.mentioned_bot is never forwarded to the InboundMessage(...) constructor — it falls back to its False default.

The internal PolicyGate works around this by re-computing the check inline (policy_gate.py), which confirms the field is known to be unreliable — but every on("message") consumer reading msg.mentioned_bot always gets False, causing "bot is @-mentioned but does not respond" bugs.

The comment path already does this correctly: _handle_comment_event passes bot_open_id=self._bot_open_id into normalize_comment.

Changes

  • pipeline.py: process() accepts an optional bot_open_id; it is forwarded to extract_mentions, and ext.mentioned_bot is now passed to InboundMessage(...).
  • channel.py: _handle_message_event passes bot_open_id=self._bot_open_id (same source the comment path uses).
  • tests/test_pipeline.py: 3 new tests — bot in mentions[]mentioned_bot=True (and the bot self-mention excluded from the public mentions list); no bot_open_idFalse; bot not mentioned → False.

Verification

  • python -m pytest lark_oapi/channel/tests — 660 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 that does not touch this code path (CI runs on Linux).

@CLAassistant

CLAassistant commented Aug 14, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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.7] InboundMessage.mentioned_bot is always False for IM messages

2 participants