fix(telegram): honour reply_to_mode="off" in DM topic fallback path#24060
Closed
KenjiChao wants to merge 1 commit into
Closed
fix(telegram): honour reply_to_mode="off" in DM topic fallback path#24060KenjiChao wants to merge 1 commit into
KenjiChao wants to merge 1 commit into
Conversation
Since b323957 ("fix(telegram): preserve DM topic routing via reply fallback"), the `telegram.reply_to_mode = "off"` user setting has been silently ignored whenever the user has DM topics configured (`platforms.telegram.extra.dm_topics`). Every bot reply gets a quote bubble of the user's message attached, even though the user explicitly opted out. The DM-topic-fallback path in `send()`, `_reply_to_message_id_for_send`, and `_thread_kwargs_for_send` unconditionally injected `reply_to_message_id` so the message would visually land in the right private-chat "topic" (Telegram DMs don't have native forum topics — Hermes fakes them via reply chains). That overrode the user preference. Fix: when `reply_to_mode == "off"`, skip the reply anchor and rely on `message_thread_id` alone for DM-topic routing. Verified live on python-telegram-bot's reference client — messages still land in the correct private topic, quote bubble gone. Two private helpers (`_reply_to_message_id_for_send`, `_thread_kwargs_for_send`) become instance methods (were @classmethod) so they can read `self._reply_to_mode`. All call sites already use `self.xxx(...)` — no caller changes needed. Tests added under `TestDmTopicReplyFallback`: - mode=off drops the implicit DM-topic reply anchor - mode=first / mode=all keep it (existing behavior preserved) - mode=off honours an explicitly provided reply_to (media reply path) - thread kwargs emit message_thread_id alone under mode=off - end-to-end send() verifies no quote bubble, topic still routed - regression guard for the b323957 DM-topic-anchor behavior Trade-off: b323957's commit message notes "either parameter alone can render outside the visible lane" on some clients. In practice on python-telegram-bot's reference client `message_thread_id` alone is sufficient. If a client genuinely needs the reply anchor for routing, users can keep `reply_to_mode = "first"` (the default) — only users who explicitly opt out are affected.
Collaborator
Contributor
|
Closing in favor of #24004 — both fix the same bug ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Since b323957 ("fix(telegram): preserve DM topic routing via reply fallback"), the
telegram.reply_to_mode = "off"user setting has been silently ignored whenever the user has DM topics configured (platforms.telegram.extra.dm_topics). Every bot reply gets a quote bubble of the user's message attached, even though the user explicitly opted out.The DM-topic-fallback path in
send(),_reply_to_message_id_for_send, and_thread_kwargs_for_sendunconditionally injectsreply_to_message_idso the message visually lands in the right private-chat "topic" (Telegram DMs don't have native forum topics — Hermes fakes them via reply chains). That override breaks the user preference.Reproduction:
→ Every bot reply still attaches a quote bubble of the user's message.
Fix
When
reply_to_mode == "off", skip the reply anchor and rely onmessage_thread_idalone for DM-topic routing. Verified live on python-telegram-bot's reference client — messages still land in the correct private topic, quote bubble gone.Two private helpers (
_reply_to_message_id_for_send,_thread_kwargs_for_send) become instance methods (were@classmethod) so they can readself._reply_to_mode. All call sites already useself.xxx(...)— no caller changes needed.Trade-off
b323957's commit message notes "either parameter alone can render outside the visible lane" on some clients. In practice on python-telegram-bot's reference client
message_thread_idalone is sufficient. If a client genuinely needs the reply anchor for routing, users can keepreply_to_mode = "first"(the default) — only users who explicitly opt out are affected by this change.Tests
New
TestDmTopicReplyFallbackclass intests/gateway/test_telegram_reply_mode.py:mode=offdrops the implicit DM-topic reply anchormode=first/mode=allkeep it (existing behavior preserved)mode=offhonours an explicitly providedreply_to(media reply path)message_thread_idalone undermode=offsend()verifies no quote bubble, topic still routedAlso verified live in production DM topic for ~30 minutes — quote bubbles gone, no message lost to wrong topic.