feat(telegram): fall back to send_document on Photo_invalid_dimensions#18444
Closed
leon7609 wants to merge 1 commit into
Closed
feat(telegram): fall back to send_document on Photo_invalid_dimensions#18444leon7609 wants to merge 1 commit into
leon7609 wants to merge 1 commit into
Conversation
Telegram rejects photos with extreme aspect ratios (most commonly very tall full-page screenshots) with `Photo_invalid_dimensions`. Previously the adapter logged the error and called the base adapter's send_image_file, which on the Telegram path silently dropped the file — the user got nothing. When send_photo raises, retry the same bytes via send_document so the original image still reaches the user (just as a file rather than an inline preview). Only fall through to the base adapter if both the photo and document attempts fail. Tested with full-page web screenshots that previously vanished; they now arrive as documents.
Collaborator
Collaborator
Contributor
Author
|
Closing as superseded by #19714 (which broadens the same idea to any send_photo failure with smarter logging — INFO for the expected dimension case, WARNING otherwise). Thanks @ee-blog and @QifengKuang for the earlier work on #15728 / #15837 that landed via #19630 / #19714. Already running the upstream behaviour locally — it works well. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Adds a
send_documentfallback to the Telegram adapter'ssend_image_filewhen Telegram rejects the photo.Telegram rejects photos with extreme aspect ratios (most commonly very tall full-page screenshots) with
Photo_invalid_dimensions. Previously the adapter logged the error and calledsuper().send_image_file(...), which on the Telegram path silently dropped the file — the user got nothing.This PR retries the same bytes via
send_documentwhensend_photoraises, so the original image still reaches the user (just as a file rather than an inline preview). Only fall through to the base adapter if both attempts fail.This complements #17833 (which added a similar
send_voice→send_documentfallback for unplayable audio formats), but for the image path.Related Issue
No existing issue — observed in the wild while sending agent-rendered web-page screenshots over Telegram.
Type of Change
Changes Made
gateway/platforms/telegram.py—send_image_file():send_photoexception: log awarning(waserror) noting we're retrying as a document.self.send_document(...)with the same bytes / caption / metadata.send_documentalso raises, log a finalerrorand fall through to the base adapter (existing behaviour).tests/gateway/test_send_image_file.py— add a case asserting the document fallback is invoked whensend_photoraisesBadRequest.How to Test
browserskill).Photo_invalid_dimensions; nothing arrives in the chat.Or run the unit tests:
Checklist
Code
feat(telegram): ...)send_voice, notsend_image_file)pytest tests/ -qand the changes don't introduce new failures (vs. main baseline)Documentation & Housekeeping