fix(gateway): route image documents through vision pipeline in Telegram - #20756
Closed
ViewWay wants to merge 2 commits into
Closed
fix(gateway): route image documents through vision pipeline in Telegram#20756ViewWay wants to merge 2 commits into
ViewWay wants to merge 2 commits into
Conversation
When users send images as documents (not as photos) in Telegram, the bot previously treated them as generic files. Now detects image file extensions (.jpg/.jpeg/.png/.webp/.gif) in document messages and routes them through the image/vision pipeline instead, enabling proper OCR and image understanding. Closes NousResearch#20128
Collaborator
liuhao1024
reviewed
May 6, 2026
liuhao1024
left a comment
Contributor
There was a problem hiding this comment.
Bug: incorrect MIME type for JPEG images
The code constructs media_types by stripping the dot from the file extension:
event.media_types = [f"image/{ext.lstrip('.')}"]But the IMAGE_MIME_TO_EXT mapping converts "image/jpeg" → .jpg, so this produces image/jpg — which is not a valid MIME type. The standard MIME type for JPEG is image/jpeg, not image/jpg.
Since doc.mime_type already holds the correct MIME type, use it directly:
event.media_types = [doc.mime_type]
Using f"image/{ext.lstrip('.')}" produces invalid MIME types like
image/jpg. The Telegram DocumentObject already provides the correct
mime_type, so use it directly. Addressing review feedback on PR NousResearch#20756.
Contributor
|
This looks implemented on current Evidence:
|
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.
Summary
When users send images as documents (not as photos) in Telegram, the bot treated them as generic files — the vision pipeline was never invoked, so no OCR or image understanding.
Changes
IMAGE_DOCUMENT_EXTSset before the video/document checks.cache_image_from_bytes(), setsevent.message_type = MessageType.IMAGE, and callshandle_message()early.IMAGE_MIME_TO_EXTfor MIME type reverse lookup.Testing
py_compile.Closes #20128