Skip to content

fix(telegram): ignore forum topic root when detecting replies to the bot - #23

Open
ibrahimsaleem wants to merge 1 commit into
BerriAI:mainfrom
ibrahimsaleem:fix/telegram-forum-topic-addressing
Open

ibrahimsaleem wants to merge 1 commit into
BerriAI:mainfrom
ibrahimsaleem:fix/telegram-forum-topic-addressing

Conversation

@ibrahimsaleem

Copy link
Copy Markdown

Summary

In forum supergroups, Telegram sets reply_to_message on every ordinary message in a
topic to the topic's forum_topic_created service message. When the bot created the
topic (for example via createForumTopic), that service message is authored by the bot.
As a result, normalize treats every message in the topic as a reply to the bot, and a
group bot responds to all conversation in that topic instead of only to messages
addressed to it.

Change

normalize now ignores a reply whose target is the topic's creation message. Explicit
replies to the bot's regular messages are still treated as addressed, and mention and
command handling are unchanged. The Python binding uses the same Rust function, so both
are covered.

Testing

  • Added a Rust unit test (bot_created_forum_topic_root_is_not_a_reply_to_the_bot) and a
    Python event test (test_topic_chatter_under_a_bot_created_topic_is_not_addressed).
    Both fail before this change and pass after it.
  • cargo test --workspace, cargo clippy -- -D warnings, cargo fmt --check,
    pytest (529 passed), ruff and mypy all pass locally.

References

Other agent frameworks have reported and fixed the same behaviour:

…the bot

Telegram sets reply_to_message on every plain message in a forum topic to the
topic's forum_topic_created service message. When the bot created the topic,
that message is authored by the bot, so all chatter in the topic passed the
reply-to-bot addressing check. Ignore replies to the topic creation message;
explicit replies to the bot's ordinary messages remain addressed.
Copilot AI balanced review requested due to automatic review settings October 14, 2026 06:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ishaan-berri

Copy link
Copy Markdown
Contributor

@ibrahimsaleem can you add screenshots of it working

@ibrahimsaleem

Copy link
Copy Markdown
Author

Thanks for taking a look! Here's a live run in a Telegram forum group. The bot is an admin and created the topic itself, and examples/telegram_echo.py is running.

Before: upstream main. A plain message in the bot-created topic, which is neither a reply nor an @mention, still reaches the agent. Telegram attaches the topic's forum_topic_created message as reply_to_message, and the bot sent that message, so main treats it as a reply to the bot.

before-upstream-main-wide

After: this PR, same topic. At 10:36, just chatting again is ignored. At 10:37, a real reply to the bot (thanks) is still answered. The 10:33 exchange at the top is the Before run.

after-this-pr-wide

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.

3 participants