Skip to content

fix(telegram): route image documents (.png/.jpg/.webp/.gif) through vision pipeline#24815

Closed
kiranvk-2011 wants to merge 1 commit into
NousResearch:mainfrom
kiranvk-code:fix/telegram-image-documents
Closed

fix(telegram): route image documents (.png/.jpg/.webp/.gif) through vision pipeline#24815
kiranvk-2011 wants to merge 1 commit into
NousResearch:mainfrom
kiranvk-code:fix/telegram-image-documents

Conversation

@kiranvk-2011

Copy link
Copy Markdown
Contributor

Summary

When users send images as documents (via Telegram file picker instead of photo button), they were rejected with "Unsupported document type" because SUPPORTED_DOCUMENT_TYPES only includes text/office formats.

This PR adds SUPPORTED_IMAGE_DOCUMENT_TYPES to handle .png, .jpg, .jpeg, .webp, and .gif files sent as documents, routing them through the image cache and vision pipeline.

Changes

  • gateway/platforms/base.py: Add SUPPORTED_IMAGE_DOCUMENT_TYPES constant (mirrors existing SUPPORTED_VIDEO_TYPES pattern)
  • gateway/platforms/telegram.py:
    • Import the new constant
    • Add MIME reverse-lookup for image types (handles .jpg/.jpegimage/jpeg dedup)
    • Route image documents through cache_image_from_bytes + vision pipeline
    • Handle media groups for image documents

Why this approach

  • Shared constant in base.py — consistent with SUPPORTED_VIDEO_TYPES, reusable by other platforms
  • MIME fallback — works even when filename has no extension but MIME type is image/*
  • Media group support — respects Telegram album/group photo behavior
  • No semantic pollution — image types are NOT added to SUPPORTED_DOCUMENT_TYPES (images are not documents)

Related Issues

Closes #20128
Closes #18620

Supersedes

This PR consolidates the fixes from several open PRs:

…ision pipeline

When users send images as documents (Telegram file picker), they were
rejected with "Unsupported document type" because SUPPORTED_DOCUMENT_TYPES
only includes text/office formats. Add SUPPORTED_IMAGE_DOCUMENT_TYPES
to base.py and handle them in telegram.py before the document check.

- Add SUPPORTED_IMAGE_DOCUMENT_TYPES constant to base.py
- Add MIME reverse-lookup for image types in telegram.py
- Route image documents through cache_image_from_bytes + vision pipeline
- Handle media groups for image documents

Closes: NousResearch#20128, NousResearch#18620
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter tool/vision Vision analysis and image generation labels May 13, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This consolidates prior PRs for the same fix: #16710, #18819, #20147, #19446, #18142. Closes #20128 and #18620. Most complete implementation (shared constant in base.py, MIME fallback, media group support).

@teknium1

Copy link
Copy Markdown
Contributor

Merged via PR #28519. Authorship preserved (rebase-merge). #28519

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 tool/vision Vision analysis and image generation type/bug Something isn't working

Projects

None yet

3 participants