Skip to content

fix(telegram): accept image files delivered as application/octet-stream - #214

Open
vinceferro wants to merge 1 commit into
grinev:mainfrom
vinceferro:fix/octet-stream-image-documents
Open

fix(telegram): accept image files delivered as application/octet-stream#214
vinceferro wants to merge 1 commit into
grinev:mainfrom
vinceferro:fix/octet-stream-image-documents

Conversation

@vinceferro

Copy link
Copy Markdown

Problem

On iOS, Send as File is the only way to share a photo at original quality. Telegram delivers it as a document with mime_type=application/octet-stream and no preview — the filename extension (.jpg) is the only type hint.

handleDocumentMessage routes on mimeType.startsWith("image/") (fast path) or the DOCUMENT_MIME_TYPES allowlist. An octet-stream .jpg matches neither, so iPhone users get the unsupported-document reply and cannot send images as files at all.

Repro

  1. iPhone → bot chat → pick photo → Share → Send as File (keep quality)
  2. Add a caption, send
  3. Bot replies that the document type isn't supported; nothing reaches the model

Fix

When mime is not image/*, fall back to the filename extension (.jpg/.jpeg/.png/.webp/.gif). If it looks like an image: normalize the file part's mime and data-URI prefix to the real type, and reuse the existing image-input capability check. Documents with proper image/* mimes keep the existing path unchanged.

Verification

Tested end-to-end against a live opencode serve with an octet-stream-delivered jpg:

result
before rejected as non-document; never reaches the model
after part arrives as image/jpeg, model describes the image correctly
[Document] Sending image document (82686 bytes, IMG_5548.JPG, image/jpeg)

Happy to adjust the extension list or move the fallback into the existing fast-path branch if maintainers prefer that shape.

iOS 'Send as File' — the highest-quality path for photos — delivers
images with mime_type=application/octet-stream and no preview; only the
filename extension reveals the type. The document handler rejected these
as unsupported documents, so iPhone users could not send images as files
at all.

Route by extension fallback when the mime is not image/*: detect .jpg/
.jpeg/.png/.webp/.gif, normalize the file part's mime (and data URI
prefix) accordingly, and reuse the existing image capability check.

Verified end-to-end against a live opencode serve: octet-stream jpg now
reaches the model as image/jpeg and gets described correctly.

Co-authored-by: opencode x-preview-f-free <noreply@opencode.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant