Skip to content

feat(channels): auto-download voice messages mirroring file path#3212

Merged
houko merged 1 commit into
librefang:mainfrom
neo-wanderer:feat/voice-auto-download
Apr 26, 2026
Merged

feat(channels): auto-download voice messages mirroring file path#3212
houko merged 1 commit into
librefang:mainfrom
neo-wanderer:feat/voice-auto-download

Conversation

@neo-wanderer

Copy link
Copy Markdown
Contributor

Summary

Closes #3211.

PR #2972 (cf308d6) added auto-download for ChannelContent::File so
agents receive a saved-on-disk path. The ChannelContent::Voice arm
of dispatch_message was missed — voice notes still flowed through as
raw [User sent a voice message (Xs): <url>] text, forcing every
agent to curl the URL and juggle workspace-allowed paths before
media_transcribe (or any other audio tool) could read the file.

This mirrors the File arm:

  • Derive a filename from the URL basename (filename_from_url),
    falling back to voice.ogg when the URL has no usable basename.
  • Call the existing download_file_to_blocks with the same
    channels.file_download_max_bytes / channels.file_download_dir
    config knobs and the same disk-cleanup sweeper.
  • Prepend a ContentBlock::Text carrying [Voice message (Xs)] plus
    any caption so the model still knows it's voice and any user
    caption survives the URL→path swap.

When the download fails the existing fallback formatter ([User sent a voice message …]) still runs — same shape as the File arm.

Test plan

  • cargo test -p librefang-channels --lib — 803/803 pass,
    including 3 new tests for filename_from_url (basic, query/fragment
    stripping, empty/unparseable URLs).
  • cargo clippy -p librefang-channels --lib --all-targets -- -D warnings — clean.
  • Build: cargo build -p librefang-channels --lib — clean.
  • Live: send a Telegram voice note to a channel-bridged agent;
    observe a [File: voice.ogg] saved to /tmp/librefang_uploads/...ogg
    block in the inbound message and that media_transcribe reads it
    directly without an agent-side download. (Tested manually on the
    reporter's setup — works end-to-end with media_transcribe against
    the saved path.)

Notes / follow-ups

PR librefang#2972 added auto-download for ChannelContent::File but the Voice
arm of dispatch_message still inlined the raw URL into the prompt
text. Agents had to curl the URL and juggle workspace-allowed paths
before media_transcribe could read the audio.

Mirror the File arm: derive a filename from the URL basename
(fallback "voice.ogg"), call download_file_to_blocks, and prepend a
context Text block carrying duration_seconds + caption so the model
still knows it's voice and any user caption survives the path swap.

Honors the same channels.file_download_max_bytes /
channels.file_download_dir config knobs and the same disk-cleanup
sweeper as File downloads.

Adds filename_from_url helper (drops query/fragment, returns None on
empty basename) with three unit tests. Closes librefang#3211.
@github-actions github-actions Bot added ready-for-review PR is ready for maintainer review area/channels Messaging channel adapters and removed ready-for-review PR is ready for maintainer review labels Apr 26, 2026
@github-actions github-actions Bot added the size/M 50-249 lines changed label Apr 26, 2026
@github-actions
github-actions Bot requested a review from houko April 26, 2026 05:26
@houko
houko merged commit 114af6e into librefang:main Apr 26, 2026
22 checks passed
@houko houko mentioned this pull request Apr 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/channels Messaging channel adapters size/M 50-249 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Voice messages bypass channel file auto-download (PR #2972 only handles File, not Voice)

2 participants