Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

docs(baileys): say what the chat list holds after a restart

Yudhi Armyndharis4a72ca645fb4
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.md
index efd62395b..8493e8538 100644
--- a/docs/06-api-specification.md
+++ b/docs/06-api-specification.md
@@ -493,6 +493,8 @@ is the instant the mute ends in epoch milliseconds (`0` = indefinite), the same
Sorted by `timestamp` DESC (most recent first) then paginated. `timestamp` is an epoch number (seconds). `kind` is the user-facing chat discriminator — one of `individual|group|channel|status|broadcast|unknown`; `isGroup` is retained for back-compat (true only for `kind: "group"`).
+On the Baileys engine the list is rebuilt from live traffic after a restart: groups come back at once, and a 1:1 chat when its next message arrives. See `docs/29-engine-capability-matrix.md` §29.7 (`getChats` after a restart).
+
**Errors:** `400` session not started · `401` · `403` · `404` session not found · `409` session not connected (also answered for a few seconds while WhatsApp Web reloads its page and the engine re-injects) · `503` page connection died mid-read, or the command timed out
#### GET /api/sessions/stats/overview
diff --git a/docs/29-engine-capability-matrix.md b/docs/29-engine-capability-matrix.md
index 71aaead95..a0b683c25 100644
--- a/docs/29-engine-capability-matrix.md
+++ b/docs/29-engine-capability-matrix.md
@@ -941,6 +941,14 @@ adapter boundary — none silently stubs.
the same engine, and the list with it.
The `sendMessage(status@broadcast, {delete})` revoke shape is _empirically unverified_: only posting
was live-spiked. On wwjs it calls `revokeStatusMessage(statusId)` (own status only).
+- **`getChats` after a restart (baileys).** Baileys keeps no chat list of its own, and WhatsApp
+ skips history sync on every connect after the first link, so a new engine (a process restart, a
+ session stop and start, or a reconnect the gateway runs itself, as for `deleteStatus` above) starts
+ with an empty one. `GET /chats` then lists the groups, re-fetched on every connect, and each 1:1
+ chat as its next message arrives; a quiet chat stays out of the list until then. Rows rebuilt this
+ way carry timestamp `0` and no `lastMessage` until a message arrives. A chat's archive, pin and mute
+ state is persisted and shows as soon as the chat is listed. The transient reconnects Baileys runs on
+ its own keep the list. whatsapp-web.js reads WhatsApp Web's own chat list and is unaffected.
- **`getContactStatus` / `getContactStatuses` (wwjs).** `Status.type` is the `text|image|video`
union — audio/other story types collapse to `text`.
- **`archiveChat` / `clearChatMessages` / `deleteChat` / `sendSeen` / `markUnread` (baileys).** The
diff --git a/src/engine/adapters/baileys-session-store.ts b/src/engine/adapters/baileys-session-store.ts
index 9c923257c..ff1e0433f 100644
--- a/src/engine/adapters/baileys-session-store.ts
+++ b/src/engine/adapters/baileys-session-store.ts
@@ -164,9 +164,14 @@ function mergeContactTwins(a: ContactTwin, b: ContactTwin): ContactTwin {
}
/**
- * Per-session, in-memory snapshot of Baileys contacts + chats, fed from `sock.ev` events. Baileys has
- * no fetch-all; this data arrives via `contacts.*`/`chats.*`/`messaging-history.set` (a full re-sync on
- * each connect) and is mapped to the neutral `Contact`/`ChatSummary` on read. Holds no socket — pure data.
+ * Per-session, in-memory snapshot of Baileys contacts + chats, fed from `sock.ev` events and mapped to
+ * the neutral `Contact`/`ChatSummary` on read. Holds no socket, pure data. Baileys has no fetch-all,
+ * and `messaging-history.set` arrives only on the first link: once the account has synced, WhatsApp
+ * skips history sync on every later connect (see BaileysHistory.hydrateNames). A new engine (a process
+ * restart, a session stop and start, a reconnect the gateway runs itself) therefore starts with no
+ * chats: the groups hydrateNames re-fetches on every open come back at once, and a 1:1 chat comes back
+ * with its next message, since Baileys emits `chats.update` for every real message. Mute, archive and
+ * pin survive through the ChatStateStore. Contacts are rebuilt from the address-book snapshot instead.
*
* Every map is LRU-bounded (`BAILEYS_SESSION_STORE_MAX_ENTRIES`, default 5000 per map, 0 = unbounded)
* because contacts/chats/lastMessages/lidToPn all grow from peer-controlled traffic — without a cap a