mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-05-08 03:01:47 +00:00
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.
This commit is contained in:
parent
ad4542bf6d
commit
f6aa1965d7
1 changed files with 17 additions and 0 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue