From 9214390f9d4405d3118d9461711e4b7ebf6a3ede Mon Sep 17 00:00:00 2001 From: Gianfranco Demarco Date: Fri, 9 Oct 2026 19:14:31 +0200 Subject: [PATCH] fix(telegram): detect remote media types with queries Co-authored-by: Cursor --- nanobot/channels/telegram/runtime.py | 3 ++- nanobot/channels/telegram/tests/test_telegram_channel.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/nanobot/channels/telegram/runtime.py b/nanobot/channels/telegram/runtime.py index de82cfb13..e00593840 100644 --- a/nanobot/channels/telegram/runtime.py +++ b/nanobot/channels/telegram/runtime.py @@ -871,7 +871,8 @@ class TelegramChannel(BaseChannel): @staticmethod def _get_media_type(path: str) -> str: """Guess media type from file extension.""" - ext = path.rsplit(".", 1)[-1].lower() if "." in path else "" + filename = urlparse(path).path if path.startswith(("http://", "https://")) else path + ext = filename.rsplit(".", 1)[-1].lower() if "." in filename else "" if ext in ("jpg", "jpeg", "png", "gif", "webp"): return "photo" if ext in ("mp4", "mov", "avi", "mkv", "webm", "3gp"): diff --git a/nanobot/channels/telegram/tests/test_telegram_channel.py b/nanobot/channels/telegram/tests/test_telegram_channel.py index b636d9e24..dd618464c 100644 --- a/nanobot/channels/telegram/tests/test_telegram_channel.py +++ b/nanobot/channels/telegram/tests/test_telegram_channel.py @@ -1920,7 +1920,7 @@ async def test_send_remote_media_url_after_security_validation(monkeypatch) -> N channel="telegram", chat_id="123", content="", - media=["https://example.com/cat.jpg"], + media=["https://example.com/cat.jpg?width=672"], ) ) @@ -1928,7 +1928,7 @@ async def test_send_remote_media_url_after_security_validation(monkeypatch) -> N { "kind": "photo", "chat_id": 123, - "photo": "https://example.com/cat.jpg", + "photo": "https://example.com/cat.jpg?width=672", "reply_parameters": None, } ]