feat(telegram): surface file metadata and support document downloads#730
Open
dorey-agent[bot] wants to merge 3 commits into
Open
feat(telegram): surface file metadata and support document downloads#730dorey-agent[bot] wants to merge 3 commits into
dorey-agent[bot] wants to merge 3 commits into
Conversation
Always pass file metadata (filename, size, mime_type) to the agent for all attachment types, even when download is skipped or fails. Changes: - Add configurable media_max_mb option (default 20MB, Telegram API limit) - Check file size before downloading — skip if over limit - Surface metadata in text label when download is skipped: [📎 Document (name=report.pdf, type=application/pdf, size=25.3MB)] - Add video/animation download support (previously fell through to unresolved text label) - Add FileMetadata struct for structured metadata extraction - Add extract_generic_metadata() for unsupported media types (sticker, location, video_note, contact) - Add format_file_size() helper for human-readable sizes The agent now always knows what was sent, regardless of whether the file was downloaded. Large/binary files that exceed the limit still surface their metadata so the agent can respond intelligently. Closes #725
VideoNote messages were falling through to the wildcard arm, returning None for metadata. Now surfaces file_size so the agent sees: [📹 Video note (size=1.2MB)]
Contributor
Author
Automated Review SummaryAgents: correctness, edge_cases ext/channels/telegram/src/dispatcher.rs:854 ext/channels/telegram/src/adapter.rs:733 ext/channels/telegram/src/dispatcher.rs:609 |
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.
Motivation
When a user sends a document (PDF, audio, video, etc.) via Telegram, the agent only receives a generic label like
[📎 Document]. No file name, size, or mime type is passed through. The agent cannot acknowledge what was sent, let alone read it.Photos are already downloaded and forwarded — other attachment types either fail silently or produce no useful metadata.
Closes #725
Solution
Always surface file metadata regardless of whether the file is downloaded:
FileMetadatastruct carriesfilename,mime_type,file_sizeextracted from Telegram message objects[📎 Document (name=report.pdf, type=application/pdf, size=25.3MB)]ContentPart::File/Audio/Imageas beforeConfigurable size threshold via
media_max_mboption (default: 20MB, Telegram Bot API hard limit):anyclaw.yamloptionsExtended media type support:
extract_generic_metadata()Design decisions:
media_max_bytesusesAtomicU64sinceSharedStateis behindArc(shared across dispatcher + adapter)bot.get_file()call to avoid unnecessary API callsTesting
Key tests:
when_process_media_video_then_sends_video_label— video routingwhen_document_message_with_caption_then_sends_label_and_caption— metadata label formattingwhen_process_media_without_caption_then_sends_placeholder— unresolved metadata stubChecklist
cargo test)cargo clippy --workspace -- -D warnings)cargo fmt --all -- --check)CHANGELOG.mdif this is a user-facing binary change (version bump 0.12.2 → 0.13.0)[ai-assisted]