feat(media): extend Telegram bot support to documents, audio, voice, and video#4
Open
Martins6 wants to merge 1 commit into
Open
feat(media): extend Telegram bot support to documents, audio, voice, and video#4Martins6 wants to merge 1 commit into
Martins6 wants to merge 1 commit into
Conversation
…and video Previously the bot's DefaultHandler only processed photos; documents, audio, voice messages, and videos were silently dropped (their media types were detected but never wired through). This change routes all five attachment types through a single media-processing path. - Add `media.MediaMetadata` struct and rewrite `BuildPrompt` to emit a metadata-rich prompt (file type, size, original name and MIME type when Telegram provides them). - Add `media.ExtractFileRef` helper that pulls the Telegram FileID, size, MIME type, original filename, MediaType subdirectory, and extension out of any `*models.Message` carrying a recognized attachment. - Refactor `internal/bot/handlers.go` DefaultHandler into a private `processMediaAttachment` helper that handles all five media types. The empty-message skip guard is simplified to rely on the resolved `userMessage` only. - Stickers, contacts, and locations remain unsupported. - Update `docs/features/feat-telegram-bot.md` to document the new behavior and prompt format; log entry in `LOG-FEATS.md`; refreshed `OVERVIEW.md` one-liner. - Add 11 unit tests covering the new helpers and prompt format; existing BuildPrompt tests updated for the new signature. All media tests pass. Verification: - `go build ./...` clean - `go vet ./...` clean - `go test ./...` all packages green
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
Previously
DefaultHandlerininternal/bot/handlers.goonly processed photo attachments; documents, audio files, voice messages, and videos were silently dropped even though their media types were already detected. This PR routes all five attachment types through a single media-processing path that mirrors the existing photo schema (download from Telegram → save under<workspace>/downloads/<type>/<UTC-timestamped-filename>→ forward a prompt that references the local file to OpenCode).Changes
internal/media/downloader.goAdd
MediaMetadatastruct (Kind, FileSize, MimeType, OriginalName).Rewrite
BuildPrompt(path, meta, caption)to emit a metadata-rich prompt:Add
ExtractFileRef(message)returning(fileID, fileSize, mimeType, originalName, mediaType, ext, ok)for any recognized attachment.internal/bot/handlers.goprocessMediaAttachmenthelper that handles all five media types through one path.mediaKindLabelfor capitalized log labels per attachment kind.userMessage.internal/media/downloader_test.goBuildPrompttests for the new signature.ExtractFileReffor each media type plus the empty-message case.docs/features/feat-telegram-bot.md— describe the new behavior and prompt format.docs/features/LOG-FEATS.md— log entry.docs/features/OVERVIEW.md— refresh the file description.Behavior
<workspace>/downloads/<type>/<UTC-timestamped-filename>.Verification
go build ./...cleango vet ./...cleango test ./...all packages green (20 tests ininternal/media/...)Test plan (requires a running bot + OpenCode CLI)
downloads/images/, prompt containsFile type: photo,File size: <N> bytes.downloads/documents/, prompt containsOriginal name: …pdf,MIME type: application/pdf.downloads/audio/with.ogg.downloads/audio/with.mp3.downloads/videos/with.mp4.