From 27df4b38822099e5cf96bab2acae76651c80e5f5 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Mon, 25 May 2026 14:45:28 -0700 Subject: [PATCH] fix(telegram): exempt reply_to_mode=off DM topic sends from anchor-required guard MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Salvage follow-up. The new private-DM-topic fail-loud contract from PR #27107 hits 'requires a reply anchor' when reply_to_mode='off' is configured, even though commit 21a15b671 (PR #23994) verified that message_thread_id alone routes correctly on python-telegram-bot's reference client when the user has explicitly opted out of quote bubbles. Carve out the explicit opt-in path so users on reply_to_mode 'off' aren't regressed — the new guard now only applies to callers that didn't ask for the anchor to be suppressed. --- gateway/platforms/telegram.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/gateway/platforms/telegram.py b/gateway/platforms/telegram.py index e8baff74e1d..64fbaee98db 100644 --- a/gateway/platforms/telegram.py +++ b/gateway/platforms/telegram.py @@ -1848,6 +1848,16 @@ class TelegramAdapter(BasePlatformAdapter): retried_thread_not_found = False metadata_reply_to = self._metadata_reply_to_message_id(metadata) private_dm_topic_send = self._is_private_dm_topic_send(chat_id, thread_id, metadata) + # reply_to_mode="off" on the existing telegram_dm_topic_reply_fallback path + # is an explicit user opt-in to "message_thread_id alone is enough" (PR #23994 + # / commit 21a15b671). Honor it — don't fail loud just because the anchor was + # suppressed by config. The new fail-loud contract only applies when the caller + # didn't ask for the anchor to be dropped. + dm_topic_reply_to_off = ( + private_dm_topic_send + and self._reply_to_mode == "off" + and bool(metadata and metadata.get("telegram_dm_topic_reply_fallback")) + ) reply_to_source = reply_to or ( str(metadata_reply_to) if private_dm_topic_send and metadata_reply_to is not None else None ) @@ -1859,7 +1869,7 @@ class TelegramAdapter(BasePlatformAdapter): else: should_thread = self._should_thread_reply(reply_to_source, i) reply_to_id = int(reply_to_source) if should_thread and reply_to_source else None - if private_dm_topic_send and reply_to_id is None: + if private_dm_topic_send and reply_to_id is None and not dm_topic_reply_to_off: return SendResult( success=False, error=self._dm_topic_missing_anchor_error(),