feat(telegram): support non-image document attachments (PDF/DOCX/etc.)#540
Open
Austin5925 wants to merge 1 commit intoop7418:mainfrom
Open
feat(telegram): support non-image document attachments (PDF/DOCX/etc.)#540Austin5925 wants to merge 1 commit intoop7418:mainfrom
Austin5925 wants to merge 1 commit intoop7418:mainfrom
Conversation
Previously, sending non-image documents (PDF, DOCX, TXT, ZIP, etc.) to a
Telegram bot fell through to the "unhandled message type" branch in the
inbound dispatch and was silently dropped. In mixed-media albums, the
album-flush loop ignored documents entirely. Both gaps left users unable
to send any non-image file via the Telegram bridge — the only working
attachment type was images.
This adds full document support, mirroring the existing image flow:
- New downloadDocument() in telegram-media.ts that preserves the
user-supplied filename and Telegram-reported MIME, so Claude can
recognize formats correctly via its Read tool.
- New processSingleDocumentMessage() in telegram-adapter.ts handling
standalone document messages.
- flushMediaGroup() now downloads non-image documents in mixed albums
with separate counts in the audit summary.
- Refactored downloadFileById to be parameterized (mime/name overrides,
size cap, kind), so all three paths (photo / image-doc / non-image-doc)
share a single implementation.
- Two new settings, mirroring the existing image_* pattern:
- bridge_telegram_document_enabled (default true)
- bridge_telegram_max_document_size (default 20 MB)
Document handling is wired into the same FileAttachment pipeline that
claude-client.ts:1037-1048 already uses for non-image files (writes to
.codepilot-uploads/ and prompts Claude to use Read tool).
Closes op7418#539
|
@Austin5925 is attempting to deploy a commit to the op7418's projects Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds non-image document attachment support to the Telegram bridge. Previously
PDFs/DOCX/TXT/ZIP files sent to a CodePilot Telegram bot were either silently
dropped (single message) or caused inconsistent failures (mixed album with
images), making the Telegram bridge unable to handle anything but images.
Closes #539
What was broken
The inbound dispatch (
telegram-adapter.ts:551-600) only recognized photosand image-MIME documents:
Non-image documents fell into the
// Unhandled message type — skipbranchat line 597 with no enqueue, no error, no acknowledgment. The album path
(
flushMediaGroup, line 791-805) similarly ignored non-image documents.CodePilot's main chat UI input already supports file attachments (per #11
and PR #508), but the Telegram bridge adapter is a separate code path that
had not been updated.
What this PR does
processSingleDocumentMessage()mirrorsprocessSingleImageMessage(), downloads the file, and enqueues with theoriginal filename + Telegram-reported MIME.
flushMediaGroupnow iterates documents inaddition to photos/image-docs, with separate counts in the audit summary.
downloadFileByIdis parameterized (mimeOverride,nameOverride,mimeFallback,nameFallback,kind) so all threepaths share a single implementation. Photo and image-doc paths preserve
their existing behavior; non-image docs use
doc.file_nameanddoc.mime_typedirectly so Claude can recognize the file format.bridge_telegram_document_enabled(defaulttrue)bridge_telegram_max_document_size(default 20 MB — Telegram Bot API limit)The downstream attachment pipeline (
claude-client.ts:1037-1048) alreadyhandles non-image files end-to-end — they're written to
.codepilot-uploads/and Claude is prompted to read them via its Read tool. No changes needed
there.
Test plan
npm run typecheck— cleannpm run test— 1143/1143 passingnpx eslint src/lib/bridge/adapters/telegram-adapter.ts src/lib/bridge/adapters/telegram-media.ts— no new warnings (only pre-existing_chatId/_draftIdunused-param warnings on line 325, unrelated to this change).pdf→ bot should reply with content analysis[image, pdf]→ bot should reply analyzing both.png(regression) → still works as beforebridge_telegram_document_enabled=false→ docs with caption fall through to text-only path; docs without caption silently skip (matches old behavior for unsupported types)Notes
discord-adapter.ts:509filtersfor
image/*only). Out of scope for this PR — happy to file separately.come from a downstream code path triggered by mixed-media albums; routing
documents through the proper enqueue path eliminates the symptom in
testing on
mainHEAD.