Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[Python lark-oapi 1.6.7] InboundMessage.mentioned_bot is always False for IM messages

未关闭 适合新手
#134 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
冷清
技术栈
python
领域
api

调研方向

从 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-oapi 1.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,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

larksuite/oapi-sdk-python 的其他 Issue

查看 larksuite/oapi-sdk-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。