fix(telegram): accept image files delivered as application/octet-stream - #214
fix(telegram): accept image files delivered as application/octet-stream#214vinceferro wants to merge 1 commit into
Conversation
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>
|
@vinceferro thanks for the PR. Major: src/bot/handlers/document-handler.ts:157-162 always uses image/jpeg for extension-based fallbacks. PNG, WebP, and GIF files are Major: src/bot/handlers/document-handler.ts:138-171 applies the filename fallback to every non-image MIME type before the known Please also add tests for octet-stream JPEG/PNG/WebP/GIF files and for MIME-type precedence with a PDF named with an image extension. |
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-streamand no preview — the filename extension (.jpg) is the only type hint.handleDocumentMessageroutes onmimeType.startsWith("image/")(fast path) or theDOCUMENT_MIME_TYPESallowlist. An octet-stream.jpgmatches neither, so iPhone users get the unsupported-document reply and cannot send images as files at all.Repro
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'smimeand data-URI prefix to the real type, and reuse the existing image-input capability check. Documents with properimage/*mimes keep the existing path unchanged.Verification
Tested end-to-end against a live opencode serve with an octet-stream-delivered jpg:
image/jpeg, model describes the image correctlyHappy to adjust the extension list or move the fallback into the existing fast-path branch if maintainers prefer that shape.