TheDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/jzszdznzzl/WABotJS/llms.txt
Use this file to discover all available pages before exploring further.
Stores.Message class is a persistent cache of WAProto.IMessage payloads, stored in a local SQLite database with a five-day time-to-live. Its primary purpose is to satisfy the getMessage callback that Baileys requires in order to support message retry: when WhatsApp asks the client to re-send a message, Baileys calls getMessage with a message ID, and this store provides the original payload. As a secondary benefit, the store merges incoming messages.update patches so the cached payload stays up to date.
In normal usage you never instantiate
Stores.Message directly. The Bot class creates and binds a Message store automatically, accessible at bot.cache.message. Construct it manually only if you are composing stores outside of the Bot abstraction.Import & construction
dir to an absolute path (relative paths are resolved against process.cwd()). The underlying database file is not opened until bind() is called.
Constructor
Directory in which the SQLite database file will be created. The store writes
to
{dir}/message_store.sqlite. The directory is created recursively if it
does not already exist.Methods
bind(sock)
messages.upsert— for every upserted message that has bothm.messageandm.key.id, the payload is serialized and stored (if not already present).messages.update— for every update, the store retrieves the existing cached payload and shallow-merges the update into it, then re-stores the result. This keeps the cached payload current with edits, reactions, and delivery receipts.
A WABotJS
Socket instance whose event emitter will be subscribed to. Passed
automatically by Bot; supply it yourself only when composing stores manually.resolve(id)
IMessage object, or undefined if the ID is unknown or the entry has expired (older than five days).
The message ID (
m.key.id) of the message to retrieve.The cached message payload, or
undefined if not found or expired.TTL and expiry
Messages are stored with a TTL of 5 days (Constants.MSG_STORE_TTL = 432_000_000 ms). A periodic background cleaner deletes rows from SQLite whose expire timestamp has passed. The cleaner interval is unref’d so it does not prevent the Node.js process from exiting cleanly. Reads also check the expire column, so an expired entry is never returned even if the cleaner has not run yet.
| Detail | Value |
|---|---|
| Database file | {dir}/message_store.sqlite |
| TTL | 432,000,000 ms (5 days) |
| Journal mode | WAL |
| Synchronous mode | NORMAL |
| L1 cache | 10-minute in-memory TTLCache in front of SQLite reads |
Serialization
WAProto.IMessage objects often contain Buffer and Uint8Array fields (e.g. media thumbnails, encryption keys). The store uses a custom JSON replacer and reviver to preserve these binary types across the serialize/deserialize round-trip:
Bufferinstances are serialized as{ type: 'Buffer', data: number[] }and restored asBuffer.Uint8Arrayinstances are serialized as{ type: 'Uint8Array', data: number[] }and restored asUint8Array.
JSON.stringify / JSON.parse unchanged. The serialized string is stored as a UTF-8 encoded BLOB in SQLite.