Skip to content

feat(messages): add GET chat history endpoint with optional media#96

Open
jgalea wants to merge 1 commit into
rmyndharis:mainfrom
jgalea:feat/chat-history-endpoint
Open

feat(messages): add GET chat history endpoint with optional media#96
jgalea wants to merge 1 commit into
rmyndharis:mainfrom
jgalea:feat/chat-history-endpoint

Conversation

@jgalea
Copy link
Copy Markdown

@jgalea jgalea commented May 19, 2026

Description

Adds a new endpoint to fetch chat history live from the WhatsApp client, bypassing the gateway's local DB. The current GET /messages only returns messages persisted since the gateway started, so historical context for any given chat is unreachable through the API today.

GET /api/sessions/:sessionId/messages/:chatId/history?limit=50&includeMedia=false

  • limit (default 50): max messages to return
  • includeMedia (default false): when true, downloads media (base64) for messages that have it. Skipped by default to keep payloads small.

Implementation

  • Add getChatHistory(chatId, limit?, includeMedia?) to IWhatsAppEngine
  • Implement in whatsapp-web-js.adapter.ts via chat.fetchMessages({ limit })
  • Wire through MessageService and MessageController
  • Unit tests added (default limit, custom limit, includeMedia pass-through)

Type of Change

  • New feature

Checklist

  • Tests added/updated (3 new tests, 26 total in message.service.spec.ts)
  • Lint passes (eslint clean on modified files)
  • Format passes (prettier check clean)
  • Build passes (nest build clean)
  • Self-reviewed
  • Documentation updated (no README/docs change needed; Swagger annotations cover it)

Testing

Tested locally against a live session:

  • Fetched a real chat with ?limit=60 and got the full 60-message history.
  • Fetched same chat with ?includeMedia=true and got base64 for 2 image messages (successfully decoded).

Adds GET /api/sessions/:sessionId/messages/:chatId/history?limit&includeMedia
to fetch chat history live from the WhatsApp client, bypassing the local DB.
Useful for retrieving messages that arrived before the gateway started.

When includeMedia=true, the adapter downloads media (base64) per message that
has it. Defaults to text-only for smaller payloads.

- Add IWhatsAppEngine.getChatHistory(chatId, limit?, includeMedia?)
- Implement in whatsapp-web-js adapter via chat.fetchMessages()
- Wire through MessageService and MessageController
- Cover with unit tests
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