Skip to content

feat: accept PDF attachments in chat - #27

Open
emanuilo wants to merge 2 commits into
mainfrom
cursor/pdf-chat-attachments-1583
Open

emanuilo wants to merge 2 commits into
mainfrom
cursor/pdf-chat-attachments-1583

Conversation

@emanuilo

@emanuilo emanuilo commented Dec 2, 2026 •

Copy link
Copy Markdown
Owner

Summary

Memclaw accepts PDF files in Telegram, Slack, and WhatsApp, extracts their text for the agent, keeps the original file, and can send that file back when asked.

How it works

  1. Platform I/O downloads the PDF (Telegram document, Slack application/pdf, WhatsApp document).
  2. memclaw/bot/pdf.py (pypdf) extracts the text, or returns a clear error.
  3. Keepable PDFs are stored like photos:
    • Telegram: the Telegram file_id (the file stays on Telegram).
    • Slack / WhatsApp: a copy under that platform's media dir (~/.memclaw/slack/ or ~/.memclaw/whatsapp/).
    • A row in the same registry as images (platform_images, kind="pdf"), plus a one-line daily note PDF file kept: name (pdf id N) so the file is linked to memory.
  4. The agent still decides whether to memory_save the extracted text. The prompt is marked [PDF] and says the file is already saved and can be returned.
  5. To send it back the agent calls pdf_search, then pdf_send (same shape as image_search / image_send). The platform sends a document, not a photo:
    • Telegram send_document (by file id)
    • Slack files_upload_v2
    • WhatsApp send_document

What is kept

Case Stored? What the user sees
Text extracted Yes Agent reply; file can be sent back later
Password-protected Yes The usual explanation, plus that the file was kept
Scanned / no extractable text Yes The usual explanation, plus that the file was kept
Over 10 MB No "Too large" message, nothing stored
Corrupt No "Not a readable PDF" message, nothing stored

Encrypted and image-only files are still real PDFs the user may want back, so they are stored even though there is no text to remember. Corrupt and oversized files are not useful or not safe to keep, so they are still rejected with no file left behind.

Try it

  1. Run Memclaw on Telegram, Slack, or WhatsApp.
  2. Send a text-based PDF (a caption is optional).
  3. Ask something about the contents, then ask for the file, e.g. "Send me that policy PDF again."

Dependency

  • pypdf>=7.2.0 (pure Python).

Tests / checks

  • tests/bot/test_pdf.py, parity coverage in tests/bot/test_parity.py, index and tool tests
  • pytest: 652 passed, 20 skipped
  • ruff check and code-shape check pass
Open in Web Open in Cursor 

cursoragent and others added 2 commits December 2, 2026 14:50
Extract text from PDFs sent on Telegram, Slack and WhatsApp, feed it
through the shared inbound pipeline like voice transcripts, and reply
clearly for oversized, encrypted, empty or corrupt files.

Co-authored-by: Emanuilo Jovanovic <emanuilo@users.noreply.github.com>
Store a received PDF the same way a photo is stored (Telegram file id,
or a file under the Slack/WhatsApp media dir) and link it to a memory
note. The agent can find it with pdf_search and send it with pdf_send
on Telegram, Slack, and WhatsApp.

Co-authored-by: Emanuilo Jovanovic <emanuilo@users.noreply.github.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.

2 participants