From 49d7210fede960796d4d0d80f5a88bfb8d45e3de Mon Sep 17 00:00:00 2001 From: MacroAnarchy Date: Mon, 30 Mar 2026 16:10:32 +0200 Subject: [PATCH] fix(gateway): parse thread_id from delivery target format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The delivery target parser uses split(':', 1) which only splits on the first colon. For the documented format platform:chat_id:thread_id (e.g. 'telegram:-1001234567890:17585'), thread_id gets munged into chat_id and is never extracted. Fix: split(':', 2) to correctly extract all three parts. Also fix to_string() to include thread_id for proper round-tripping. The downstream plumbing in _deliver_to_platform() already handles thread_id correctly (line 292-293) — it just never received a value. --- gateway/delivery.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/gateway/delivery.py b/gateway/delivery.py index 5adb3c2c1..fff0aeadf 100644 --- a/gateway/delivery.py +++ b/gateway/delivery.py @@ -70,12 +70,15 @@ class DeliveryTarget: if target == "local": return cls(platform=Platform.LOCAL) - # Check for platform:chat_id format + # Check for platform:chat_id or platform:chat_id:thread_id format if ":" in target: - platform_str, chat_id = target.split(":", 1) + parts = target.split(":", 2) + platform_str = parts[0] + chat_id = parts[1] if len(parts) > 1 else None + thread_id = parts[2] if len(parts) > 2 else None try: platform = Platform(platform_str) - return cls(platform=platform, chat_id=chat_id, is_explicit=True) + return cls(platform=platform, chat_id=chat_id, thread_id=thread_id, is_explicit=True) except ValueError: # Unknown platform, treat as local return cls(platform=Platform.LOCAL) @@ -94,6 +97,8 @@ class DeliveryTarget: return "origin" if self.platform == Platform.LOCAL: return "local" + if self.chat_id and self.thread_id: + return f"{self.platform.value}:{self.chat_id}:{self.thread_id}" if self.chat_id: return f"{self.platform.value}:{self.chat_id}" return self.platform.value