Skip to main content

Documentation Index

Fetch the complete documentation index at: https://whiskeysockets-docs-jids-socket-config-ptbr.mintlify.app/llms.txt

Use this file to discover all available pages before exploring further.

After connecting successfully, the socket downloads and processes your existing chats, contacts, and messages from WhatsApp. This data arrives asynchronously through the messaging-history.set event.

Handling the history payload

Listen for messaging-history.set and persist the data however you like. At minimum, store messages so you can return them from your getMessage callback.
sock.ev.on('messaging-history.set', ({
  chats: newChats,
  contacts: newContacts,
  messages: newMessages,
  syncType,
}) => {
  // Persist chats, contacts, and messages to your store
})
syncType tells you which kind of sync delivered the payload (full vs. incremental), so you can decide whether to overwrite or merge.

Requesting full history

By default, Baileys connects with a Chrome browser profile, which limits how much history WhatsApp returns on the initial sync. To get full history, use the macOS desktop browser preset and set syncFullHistory:
import makeWASocket, { Browsers } from '@whiskeysockets/baileys'

const sock = makeWASocket({
  browser: Browsers.macOS('Desktop'),
  syncFullHistory: true,
})
Full-history sync significantly increases startup time and memory on large accounts.

Disabling history sync

If you don’t want history at all, return false from shouldSyncHistoryMessage:
const sock = makeWASocket({
  shouldSyncHistoryMessage: () => false,
})

On-demand history sync

Beyond the initial sync, you can ask the main device for older messages at any time using sock.fetchMessageHistory:
await sock.fetchMessageHistory(/* count, oldestMsgKey, oldestMsgTimestamp */)
This is useful for paginating through history on demand instead of pulling everything up front.