Skip to content

fix(gateway): route image documents through vision pipeline in Telegram - #20756

Closed
ViewWay wants to merge 2 commits into
NousResearch:mainfrom
ViewWay:fix/telegram-image-documents
Closed

fix(gateway): route image documents through vision pipeline in Telegram#20756
ViewWay wants to merge 2 commits into
NousResearch:mainfrom
ViewWay:fix/telegram-image-documents

Conversation

@ViewWay

@ViewWay ViewWay commented May 6, 2026

Copy link
Copy Markdown
Contributor

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

  • Added IMAGE_DOCUMENT_EXTS set before the video/document checks.
  • If the file extension matches an image type, downloads, caches via cache_image_from_bytes(), sets event.message_type = MessageType.IMAGE, and calls handle_message() early.
  • Added IMAGE_MIME_TO_EXT for MIME type reverse lookup.

Testing

  • Syntax verified with py_compile.

Closes #20128

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
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter comp/gateway Gateway runner, session dispatch, delivery tool/vision Vision analysis and image generation labels May 6, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Duplicate of #16710 (and #20700, #18819) — all route Telegram image documents through the photo/vision pipeline. See #20128.

@liuhao1024 liuhao1024 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@teknium1

Copy link
Copy Markdown
Contributor

This looks implemented on current main; closing as an automated hermes-sweeper review.

Evidence:

  • gateway/platforms/telegram.py:5652 now normalizes Telegram document MIME types and reverse-lookups image extensions from _TELEGRAM_IMAGE_MIME_TO_EXT.
  • gateway/platforms/telegram.py:5678 routes image document uploads through cache_image_from_bytes(), sets event.message_type = MessageType.PHOTO, fills event.media_urls / event.media_types, and enqueues via the photo/media-group path instead of the generic document path.
  • The implementing commit is 77c4675a50db7abbfd191d4fba4746b4f3e1559e (fix(telegram): route image documents (.png/.jpg/.webp/.gif) through vision pipeline), which explicitly closes #20128.
  • The linked discussion here already identified this PR as one of several duplicates for the same Telegram image-document routing fix.

@teknium1 teknium1 closed this Jun 11, 2026
@teknium1 teknium1 added the sweeper:implemented-on-main Sweeper: behavior already present on current main label Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/telegram Telegram bot adapter sweeper:implemented-on-main Sweeper: behavior already present on current main tool/vision Vision analysis and image generation type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Telegram: image documents like .webp are rejected as unsupported documents instead of being routed through image handling

4 participants