Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

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

Open Beginner friendly
#134 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
python
Domain
api

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.

Description

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
    ...
)
Dominant language
Python
Stars
560
Forks
102
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from larksuite/oapi-sdk-python

All issues in larksuite/oapi-sdk-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.