From 5338250dab14b3e4f9dfb306446e8c55835adfad Mon Sep 17 00:00:00 2001 From: Timur00Kh <32297275+Timur00Kh@users.noreply.github.com> Date: Sun, 17 May 2026 00:28:24 +0400 Subject: [PATCH] fix(gateway): add direct_messages_topic_id for synthetic Telegram DM events When /goal loop generates synthetic MessageEvents (goal continuations, status notices), the reply anchor is unavailable (message_id=None). For Telegram DM topic lanes, the Telegram adapter requires direct_messages_topic_id to route messages correctly; without it, the adapter falls back to message_thread_id=None, sending messages to the root 'All Messages' thread instead of the active topic lane. The fix includes direct_messages_topic_id in thread metadata for all non-General Telegram DM topics, ensuring queued/synthetic messages are delivered to the correct thread even when no reply anchor exists. --- gateway/run.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gateway/run.py b/gateway/run.py index 458603c3115..56185190e26 100644 --- a/gateway/run.py +++ b/gateway/run.py @@ -12546,6 +12546,12 @@ class GatewayRunner: and getattr(source, "chat_type", None) == "dm" ): metadata["telegram_dm_topic_reply_fallback"] = True + # Telegram DM topic lanes need direct_messages_topic_id in metadata + # so synthetic/queued messages (goal continuations, status notices) + # route to the correct topic even when reply anchor is unavailable. + tid = str(thread_id) + if tid and tid not in {"", "1"}: + metadata["direct_messages_topic_id"] = tid anchor = reply_to_message_id or getattr(source, "message_id", None) if anchor is not None: metadata["telegram_reply_to_message_id"] = str(anchor)