From 41545f7ec59dfe9b05f58374113635eeae0d1bfc Mon Sep 17 00:00:00 2001 From: helix4u <4317663+helix4u@users.noreply.github.com> Date: Tue, 5 May 2026 13:36:33 -0600 Subject: [PATCH] fix(telegram): keep DM topic typing scoped --- gateway/platforms/telegram.py | 11 ++++++----- .../gateway/test_telegram_thread_fallback.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/gateway/platforms/telegram.py b/gateway/platforms/telegram.py index ad5ed66920..51b2bc848a 100644 --- a/gateway/platforms/telegram.py +++ b/gateway/platforms/telegram.py @@ -2516,11 +2516,12 @@ class TelegramAdapter(BasePlatformAdapter): ) except Exception as e: if message_thread_id is not None and self._is_thread_not_found_error(e): - await self._bot.send_chat_action( - chat_id=int(chat_id), - action="typing", - message_thread_id=None, - ) + if str(_typing_thread) == self._GENERAL_TOPIC_THREAD_ID: + await self._bot.send_chat_action( + chat_id=int(chat_id), + action="typing", + message_thread_id=None, + ) else: raise except Exception as e: diff --git a/tests/gateway/test_telegram_thread_fallback.py b/tests/gateway/test_telegram_thread_fallback.py index 4930467bfe..3b7069d6fa 100644 --- a/tests/gateway/test_telegram_thread_fallback.py +++ b/tests/gateway/test_telegram_thread_fallback.py @@ -179,6 +179,25 @@ async def test_send_typing_retries_without_general_thread_when_not_found(): ] +@pytest.mark.asyncio +async def test_send_typing_does_not_fall_back_to_root_for_dm_topic(): + """Typing failures in DM topics should not show an indicator in All Messages.""" + adapter = _make_adapter() + call_log = [] + + async def mock_send_chat_action(**kwargs): + call_log.append(dict(kwargs)) + raise FakeBadRequest("Message thread not found") + + adapter._bot = SimpleNamespace(send_chat_action=mock_send_chat_action) + + await adapter.send_typing("12345", metadata={"thread_id": "22182"}) + + assert call_log == [ + {"chat_id": 12345, "action": "typing", "message_thread_id": 22182}, + ] + + @pytest.mark.asyncio async def test_send_retries_without_thread_on_thread_not_found(): """When message_thread_id causes 'thread not found', retry without it."""