Skip to content

Fix document MIME types and add FileName to DocumentMessage#199

Open
CaceresCallieri wants to merge 1 commit intolharries:mainfrom
CaceresCallieri:fix/document-mime-types-and-filename
Open

Fix document MIME types and add FileName to DocumentMessage#199
CaceresCallieri wants to merge 1 commit intolharries:mainfrom
CaceresCallieri:fix/document-mime-types-and-filename

Conversation

@CaceresCallieri
Copy link
Copy Markdown

Summary

  • Documents (PDFs, Office files, etc.) are sent with application/octet-stream MIME type and no FileName field, causing them to appear as "Untitled" without preview in WhatsApp.
  • File extension extraction uses manual string slicing which can produce incorrect results when the file path has no extension.

Changes

  • Add explicit MIME types for common document formats: PDF, DOC/DOCX, XLS/XLSX, PPT/PPTX, CSV, TXT, ZIP
  • Use correct IANA-registered OOXML MIME types for modern Office formats (e.g., application/vnd.openxmlformats-officedocument.wordprocessingml.document for .docx)
  • Add FileName field to DocumentMessage so WhatsApp displays the actual filename instead of "Untitled"
  • Replace manual string slicing (strings.LastIndex) with filepath.Ext and filepath.Base for safer path handling

Test plan

  • Sent a PDF via send_file — confirms it now shows with title and preview in WhatsApp
  • Verify DOCX, XLSX, PPTX render with correct icons and previews
  • Verify unknown extensions still fall through to application/octet-stream

Documents (PDFs, Office files, etc.) were sent with
application/octet-stream MIME type and no FileName field, causing
them to appear as "Untitled" without preview in WhatsApp.

Changes:
- Add explicit MIME types for PDF, DOC/DOCX, XLS/XLSX, PPT/PPTX,
  CSV, TXT, ZIP with correct IANA-registered types (including
  OOXML types for modern Office formats)
- Add FileName field to DocumentMessage so WhatsApp displays the
  actual filename instead of "Untitled"
- Use filepath.Ext and filepath.Base instead of manual string
  slicing for safer path handling (fixes edge case when path has
  no extension)
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