Skip to content

feat: support Discord file attachments#165

Closed
DrVictorChen wants to merge 1 commit intoopenabdev:mainfrom
DrVictorChen:feat/discord-attachment-support
Closed

feat: support Discord file attachments#165
DrVictorChen wants to merge 1 commit intoopenabdev:mainfrom
DrVictorChen:feat/discord-attachment-support

Conversation

@DrVictorChen
Copy link
Copy Markdown

@DrVictorChen DrVictorChen commented Apr 9, 2026

Summary

  • Discord users can now send files (PDFs, images, code, etc.) alongside messages
  • Attachments are downloaded to /tmp/openab_attachments/{thread_id}/ and file paths are appended to the prompt text, so any ACP backend agent can read them with its native file tools — no ACP protocol changes needed

Related: #161 (feature request for multimodal support), #158 (image-only via ACP ImageContent blocks). This PR takes a complementary approach — downloading all file types to disk and injecting paths into the prompt, which works for PDFs, code files, and other non-image attachments without requiring ACP protocol changes. The two approaches (#158 for images, this PR for general files) could coexist.

How it works

User sends message + PDF in Discord
         │
         ▼
OpenAB downloads attachment to /tmp/openab_attachments/{thread_id}/paper.pdf
         │
         ▼
Prompt becomes:
  "Please summarize this paper
  
   Attached files:
   - /tmp/openab_attachments/123456/paper.pdf (application/pdf, 2.3 MB)"
         │
         ▼
ACP agent reads the file path with its own file read tool

Changes

File Change
Cargo.toml Add reqwest (rustls-tls, matching serenity's TLS backend)
src/discord.rs Add download_attachments(), inject paths into prompt, allow attachment-only messages
src/acp/pool.rs Clean up temp attachment directory when sessions are garbage-collected

Safety

  • Filenames sanitized (only alphanumeric, ., -, _)
  • Max 25 MB per file, max 5 attachments per message
  • Download failure → graceful fallback (includes Discord CDN URL instead)
  • Temp files cleaned up on session cleanup

Test plan

  • cargo build --release passes
  • Send text-only message → behavior unchanged
  • Send PDF attachment → agent receives file path and can read content
  • Send attachment without text → prompt contains only attachment info (not rejected as empty)
  • Send file >25 MB → skipped with friendly message
  • Session cleanup → /tmp/openab_attachments/{thread_id}/ removed

🤖 Generated with Claude Code

Discord users can now send files (PDFs, images, code, etc.) alongside
their messages. The handler downloads attachments to a local temp
directory and appends the file paths to the prompt text, so any ACP
backend agent can read them with its native file tools.

Details:
- Download attachments to /tmp/openab_attachments/{thread_id}/
- Sanitize filenames to prevent path traversal
- Skip files >25 MB, limit 5 attachments per message
- Graceful fallback: on download failure, include the Discord CDN URL
- Allow attachment-only messages (no text required)
- Clean up temp files when sessions are garbage-collected

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant