larksuite / larksuite/oapi-sdk-python
[Python lark-oapi 1.6.7] InboundMessage.mentioned_bot is always False for IM messages
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 559
- Forks
- 102
- PR merge metrics
- No merged PRs in 30d
Description
Environment
- Package:
lark-oapi1.6.7 (Python) - Python: 3.9+
- Affected path:
lark_oapi/channel/normalize/pipeline.py
Summary
InboundMessage.mentioned_bot is unconditionally False for all IM (text/post) messages, even when the bot is explicitly mentioned and the bot identity is fully resolved.
Root Cause
Two compounding omissions in lark_oapi/channel/normalize/pipeline.py:
1. bot_open_id not passed to extract_mentions (line 163)
# pipeline.py:163 — current (broken)
ext = extract_mentions(raw_mentions)
mentions.py:147 only sets ext.mentioned_bot = True when bot_open_id and parsed.open_id == bot_open_id. Since bot_open_id is never passed, ext.mentioned_bot stays False for every IM message.
2. mentioned_bot not forwarded to InboundMessage (lines 253-266)
Even if ext.mentioned_bot were computed, it is never passed to the InboundMessage(...) constructor — only mentions= and mentioned_all= are. The field falls back to its default False (types.py:387). pipeline.py contains no reference to mentioned_bot at all.
Evidence: SDK works around its own bug internally
policy_gate.py:142-143 re-computes the bot-mention check inline rather than trusting msg.mentioned_bot:
mentioned_bot = bool(
bot_open_id and any(m.open_id == bot_open_id for m in msg.mentions)
)
This confirms the maintainers know the field is unreliable; the internal gate self-heals, but the public-facing field exposed to on("message") consumers was never fixed.
Contrast with the comment path (correct)
comment.py:112 computes mentioned_bot_flag and :137 passes mentioned_bot=mentioned_bot_flag to the comment event. Only the IM path is broken.
Impact
Any consumer reading msg.mentioned_bot in an on("message") handler always receives False, causing "bot is @-mentioned in a group but does not respond" bugs. Verified empirically: with the bot present in mentions and bot_identity resolved, msg.mentioned_bot was still False.
Suggested Fix
In pipeline.py, obtain bot_open_id (same source as policy_gate), pass it to extract_mentions, and forward the result:
bot_open_id = getattr(self._cfg.app, "bot_open_id", None)
ext = extract_mentions(raw_mentions, bot_open_id=bot_open_id)
...
return InboundMessage(
...
mentions=mentions,
mentioned_all=mentioned_all,
mentioned_bot=ext.mentioned_bot, # ADD THIS
...
)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in lark_oapi/channel/normalize/pipeline.py and compare its IM-message flow with mentions.py, policy_gate.py, and comment.py. Trace bot_open_id and the InboundMessage constructor; done means an explicitly mentioned bot produces mentioned_bot=True for IM messages while existing mention fields remain intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100