fix(telegram): route image documents (.webp, .png, .jpg, .gif) through image handling (#20128)#20147
Closed
Sanjays2402 wants to merge 4 commits into
Closed
fix(telegram): route image documents (.webp, .png, .jpg, .gif) through image handling (#20128)#20147Sanjays2402 wants to merge 4 commits into
Sanjays2402 wants to merge 4 commits into
Conversation
Image extensions (.jpg/.jpeg/.png/.webp/.gif) sometimes arrive on platforms as 'documents' rather than native photo attachments (e.g. Telegram users picking from the file picker, sticker exporters wrapping images as files). Centralize the ext -> MIME mapping in base so adapters can route those bytes through the image pipeline instead of rejecting them as unsupported documents. Refs NousResearch#20128
Telegram users who upload an image via the file picker (instead of the native photo button) deliver the image as msg.document. Common formats like .webp were rejected with 'Unsupported document type' because the document branch only checked SUPPORTED_DOCUMENT_TYPES / SUPPORTED_VIDEO_TYPES. Add a SUPPORTED_IMAGE_DOCUMENT_TYPES branch that downloads the bytes, caches them via cache_image_from_bytes, sets media_urls/media_types, flips message_type to PHOTO, and routes through the existing photo-batch / media-group buffering so the vision/image pipeline picks them up exactly like native photos. The MIME-to-extension fallback now also recognizes image MIME types when the filename is missing, and the unsupported-type message lists the new image extensions. Fixes NousResearch#20128
Adds TestImageDocuments covering the regression in NousResearch#20128: * .webp document is downloaded, cached, and emitted as a PHOTO event via the photo-batching path. * .jpg / .jpeg / .png / .gif documents take the same path (parametrized). * Captions are preserved on the merged event. * Multi-image albums (media_group_id) collapse into one PHOTO event with both media_urls. * MIME-only resolution works when filename is missing. * The 'Unsupported document type' message now lists image extensions. * Download exceptions don't crash the handler. Also adds IMAGE_CACHE_DIR redirection to the autouse cache fixture so the new tests don't write into ~/.hermes.
Collaborator
Contributor
|
Automated hermes-sweeper review: this Telegram image-document fix is already implemented on current main. Evidence:
Thanks for the contribution and for tying it back to #20128. The maintainer note that this duplicated #16710 matches what is now present on main. |
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.
Closes #20128.
When a user sent an image to Telegram as a document (instead of as a normal photo), Hermes rejected formats like
.webpwithUnsupported document type '.webp'even though the same file uploaded as a photo would have worked. Existing handling only consideredSUPPORTED_DOCUMENT_TYPESandSUPPORTED_VIDEO_TYPES.Fix
SUPPORTED_IMAGE_DOCUMENT_TYPESmapping (.jpg,.jpeg,.png,.webp,.gif) ongateway/platforms/base.py.gateway/platforms/telegram.py'smsg.documentpath: resolves extension from filename or MIME type (so docs without filenames still work), downloads bytes, caches viacache_image_from_bytes(...), populatesevent.media_urls/event.media_types, setsmessage_type = MessageType.PHOTO, and routes through the existing photo enqueue path._enqueue_photo_event/_queue_media_group_eventso albums / bursts of mixed image-documents merge into a single event, identical to nativemsg.photouploads.Test
10 new cases in
TestImageDocuments(withintests/gateway/test_telegram_documents.py) covering: each of the 5 image extensions, MIME-only resolution, album buffering, mixed image+photo albums, and the updated unsupported-type message.pytest tests/gateway/test_telegram_documents.py→ 49 passed.Notes
MessageTypeonly definesPHOTO(notIMAGE), so usedPHOTOto match the existing photo path — image documents now produce identical events to native photos.## Unreleased / ### Fixesto host the entry.