Baileys Instance icon

Baileys Instance

Use the wa-instance API built on Baileys 7

History Sync → Fetch

AI-generated

Summary

Fetches older messages from a WhatsApp chat using the wa-instance's history sync API, starting from a reference message or timestamp.

Inputs

  • Chat JID (required) — The JID of the chat from which to fetch the message history.
  • Count (required) — The number of older messages to fetch, between 1 and 200, defaulting to 50.
  • Oldest Message ID — The ID of the oldest message already present locally to fetch messages older than this.
  • Additional Options — Optional filters including 'From Me' (to fetch messages sent by you), 'Oldest Message Timestamp' (Unix timestamp in seconds for oldest message not present locally), and 'Participant' (a specific participant's JID to filter messages).

Output shape

a single JSON object containing the fetched older messages and related metadata

The output is the JSON response from the wa-instance's /history-sync/fetch endpoint, reflecting the requested older messages. Ensure the 'Chat JID' is specified to target the desired chat context.

Examples

Example 1: Fetch 100 older messages from a chat starting from a known message ID

Set the 'Chat JID' to the chat to sync, 'Count' to 100, and 'Oldest Message ID' to the last known oldest message. Optionally set 'From Me' to true to limit to messages you sent.

Links

Discussion