fix(telegram): detect remote media types with queries

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Gianfranco DemarcoandCursor authored and Xubin Ren committed 2026-10-18 17:38:49 +08:00
1 parent 6baf7178a8
commit 9214390f9d
2 files changed
+4 -3

No files matched your search

+2 -1
View File
@@ -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"):
@@ -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,
}
]