[Python lark-oapi 1.6.7] InboundMessage.mentioned_bot is always False for IM messages
还没有人认领这个 Issue。
评估
调研方向
从 lark_oapi/channel/normalize/pipeline.py 开始,将其 IM 消息流程与 mentions.py、policy_gate.py 和 comment.py 进行比较。跟踪 bot_open_id 和 InboundMessage 构造函数;当被明确提及的 bot 为 IM 消息生成 mentioned_bot=True,同时现有的提及字段保持不变时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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
...
)
- 主要语言
- Python
- 星标
- 559
- 派生
- 102
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
larksuite/oapi-sdk-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 67/100
larksuite/oapi-sdk-python#163 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 82/100
larksuite/oapi-sdk-python#162 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 94/100
larksuite/oapi-sdk-python#161 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
larksuite/oapi-sdk-python#160 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
larksuite/oapi-sdk-python#159 ·
查看 larksuite/oapi-sdk-python 的全部 Issue
相似的 Issue
-
docs pydanty:is-working
难度 2/5 1-3 小时 新手友好度 75/100
pydantic/pydantic-ai#8863 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
run-llama/llama_index#23278 ·
维护者通常 2 天内回复
-
documentation from-review-extraction github-actions priority: low severity:nit
难度 1/5 1 小时以内 新手友好度 92/100
LearningCircuit/local-deep-research#6946 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
oracle/langchain-oracle#323 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
tenstorrent/tt-metal#58057 · 1 条评论 ·
维护者通常 1 天内回复