From f6aa1965d79b2285bb5097979085562876f9a0c7 Mon Sep 17 00:00:00 2001 From: ee-blog <52785845+ee-blog@users.noreply.github.com> Date: Sun, 26 Apr 2026 01:09:55 +0800 Subject: [PATCH] fix(telegram): fallback to document when photo dimensions exceed limits Telegram's send_photo has dimension limits (sum of width+height <= 10000px). When sending large screenshots or tall images, the API returns 'Photo_invalid_dimensions' error. Fix: Catch this specific error in send_image_file() and automatically fallback to send_document() which has no dimension limits (only 50MB size). This is similar to the existing 5MB URL fallback (commit 542faf22) but handles local files with dimension issues instead of URL size issues. --- gateway/platforms/telegram.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/gateway/platforms/telegram.py b/gateway/platforms/telegram.py index 188038a1ad..247b5fbb93 100644 --- a/gateway/platforms/telegram.py +++ b/gateway/platforms/telegram.py @@ -2267,6 +2267,23 @@ class TelegramAdapter(BasePlatformAdapter): ) return SendResult(success=True, message_id=str(msg.message_id)) except Exception as e: + error_str = str(e) + # Check for dimension-related errors - fallback to document mode + if "Photo_invalid_dimensions" in error_str or "PHOTO_INVALID_DIMENSIONS" in error_str: + logger.info( + "[%s] Image dimensions exceed Telegram photo limits, sending as document: %s", + self.name, + image_path, + ) + # Fallback to sending as document (file) - no dimension limits, only 50MB size limit + return await self.send_document( + chat_id=chat_id, + file_path=image_path, + caption=caption, + file_name=os.path.basename(image_path), + reply_to=reply_to, + metadata=metadata, + ) logger.error( "[%s] Failed to send Telegram local image, falling back to base adapter: %s", self.name,