hermes - ✅(Solved) Fix Telegram: image documents like .webp are rejected as unsupported documents instead of being routed through image handling [1 pull requests, 3 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#20128Fetched 2026-05-06 06:38:33
View on GitHub
Comments
3
Participants
2
Timeline
9
Reactions
0
Timeline (top)
labeled ×4commented ×3cross-referenced ×2

Root Cause

In gateway/platforms/telegram.py, the msg.document branch:

  • resolves extensions from filename / MIME type
  • handles video documents
  • handles generic supported documents
  • but does not have a dedicated branch for image documents

As a result, image files sent as Telegram documents are rejected unless they happen to be uploaded as msg.photo.

Fix Action

Fixed

PR fix notes

PR #20147: fix(telegram): route image documents (.webp, .png, .jpg, .gif) through image handling (#20128)

Description (problem / solution / changelog)

Closes #20128.

When a user sent an image to Telegram as a document (instead of as a normal photo), Hermes rejected formats like .webp with Unsupported document type '.webp' even though the same file uploaded as a photo would have worked. Existing handling only considered SUPPORTED_DOCUMENT_TYPES and SUPPORTED_VIDEO_TYPES.

Fix

  • Added SUPPORTED_IMAGE_DOCUMENT_TYPES mapping (.jpg, .jpeg, .png, .webp, .gif) on gateway/platforms/base.py.
  • New image-document branch in gateway/platforms/telegram.py's msg.document path: resolves extension from filename or MIME type (so docs without filenames still work), downloads bytes, caches via cache_image_from_bytes(...), populates event.media_urls / event.media_types, sets message_type = MessageType.PHOTO, and routes through the existing photo enqueue path.
  • Reuses _enqueue_photo_event / _queue_media_group_event so albums / bursts of mixed image-documents merge into a single event, identical to native msg.photo uploads.
  • Updated the unsupported-type message to list the union of document and image extensions (sorted).

Test

10 new cases in TestImageDocuments (within tests/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

  • MessageType only defines PHOTO (not IMAGE), so used PHOTO to match the existing photo path — image documents now produce identical events to native photos.
  • No CHANGELOG.md existed in the repo before this PR; created one with ## Unreleased / ### Fixes to host the entry.
  • Existing video / generic-document handling is untouched.

Changed files

  • CHANGELOG.md (added, +14/-0)
  • gateway/platforms/base.py (modified, +20/-0)
  • gateway/platforms/telegram.py (modified, +46/-1)
  • tests/gateway/test_telegram_documents.py (modified, +173/-0)

Code Example

SUPPORTED_IMAGE_DOCUMENT_TYPES = {
    ".jpg": "image/jpeg",
    ".jpeg": "image/jpeg",
    ".png": "image/png",
    ".webp": "image/webp",
    ".gif": "image/gif",
}
RAW_BUFFERClick to expand / collapse

Bug description

When a user sends an image to Hermes via Telegram as a document (instead of as a normal photo), Hermes rejects certain image formats such as .webp with:

Unsupported document type '.webp'. Supported types: .cfg, .csv, .docx, .ini, .json, .log, .md, .pdf, .pptx, .toml, .txt, .xlsx, .xml, .yaml, .yml, .zip

This is confusing because .webp is a valid image format and should be processed through the normal image/vision pipeline.

Steps to reproduce

  1. Use the Telegram gateway.
  2. Send a .webp image as a document/file (not as a Telegram photo).
  3. Observe that Hermes responds with: Unsupported document type '.webp'...

Expected behavior

Telegram image documents such as:

  • .jpg
  • .jpeg
  • .png
  • .webp
  • .gif

should be treated as images, cached into the image cache, and routed through the same image analysis path as normal Telegram photos.

Actual behavior

The Telegram adapter currently checks document extensions only against SUPPORTED_DOCUMENT_TYPES and SUPPORTED_VIDEO_TYPES.

If the uploaded file is an image document like .webp, it falls through to the unsupported-document branch.

Root cause

In gateway/platforms/telegram.py, the msg.document branch:

  • resolves extensions from filename / MIME type
  • handles video documents
  • handles generic supported documents
  • but does not have a dedicated branch for image documents

As a result, image files sent as Telegram documents are rejected unless they happen to be uploaded as msg.photo.

Proposed fix

Add a dedicated image-document mapping and branch in the Telegram adapter.

Example approach

In gateway/platforms/telegram.py:

  1. Introduce something like:
SUPPORTED_IMAGE_DOCUMENT_TYPES = {
    ".jpg": "image/jpeg",
    ".jpeg": "image/jpeg",
    ".png": "image/png",
    ".webp": "image/webp",
    ".gif": "image/gif",
}
  1. In the msg.document handling path:
  • resolve image extensions from MIME type as well
  • if ext in SUPPORTED_IMAGE_DOCUMENT_TYPES:
    • download bytes
    • cache via cache_image_from_bytes(...)
    • set:
      • event.media_urls
      • event.media_types
      • event.message_type = MessageType.IMAGE
    • enqueue through the photo/image path instead of the document path
  1. Update the unsupported-type message so the supported image-document extensions are included in the reported list.

Notes

I locally verified that this approach fixes .webp uploads sent via Telegram as documents and routes them correctly into image analysis.

Relevant area:

  • gateway/platforms/telegram.py
  • current unsupported-document branch around the msg.document handling logic

Environment

  • Hermes Agent v0.12.0
  • Telegram gateway

extent analysis

TL;DR

Add a dedicated image-document mapping and branch in the Telegram adapter to handle image files sent as documents.

Guidance

  • Introduce a SUPPORTED_IMAGE_DOCUMENT_TYPES dictionary to map image extensions to their corresponding MIME types.
  • Update the msg.document handling path to resolve image extensions from MIME type and check if the extension is in SUPPORTED_IMAGE_DOCUMENT_TYPES.
  • If the extension is supported, download the bytes, cache the image, and set the necessary event properties to route the image through the photo/image path.
  • Update the unsupported-type message to include the supported image-document extensions.

Example

SUPPORTED_IMAGE_DOCUMENT_TYPES = {
    ".jpg": "image/jpeg",
    ".jpeg": "image/jpeg",
    ".png": "image/png",
    ".webp": "image/webp",
    ".gif": "image/gif",
}

Notes

The proposed fix has been locally verified to work for .webp uploads sent via Telegram as documents, but it may require further testing to ensure it works for all supported image formats.

Recommendation

Apply the proposed workaround by adding the dedicated image-document mapping and branch in the Telegram adapter, as it has been verified to fix the issue for .webp uploads and is likely to work for other supported image formats.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Telegram image documents such as:

  • .jpg
  • .jpeg
  • .png
  • .webp
  • .gif

should be treated as images, cached into the image cache, and routed through the same image analysis path as normal Telegram photos.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

hermes - ✅(Solved) Fix Telegram: image documents like .webp are rejected as unsupported documents instead of being routed through image handling [1 pull requests, 3 comments, 2 participants]