After connecting a WhatsApp client with Baileys, I’m no longer able to sync historical messages using the approach that previously worked.
I used to rely on two internal methods on the socket:
• socket.loadMessages(jid, limit)
• socket.requestMessageHistorySync(jid)
After updating Baileys, both of these are now undefined on the socket instance, so my sync logic no longer works
My sync code looks like this:
// Option 1: Try to use the socket's internal loadMessages if available
if (typeof (instance.socket as any).loadMessages === "function") {
try {
const messages = await (instance.socket as any).loadMessages(jid, 50);
if (messages && messages.length > 0) {
console.log(`Loaded ${messages.length} messages for ${jid}`);
await this.handleIncomingMessages(instanceId, messages);
}
} catch (loadError) {
console.log(`loadMessages not available or failed: ${loadError}`);
}
}
// Option 2: Request message sync through protocol
// This was supposed to trigger the messaging-history.set event handler
if (typeof (instance.socket as any).requestMessageHistorySync === "function") {
try {
await (instance.socket as any).requestMessageHistorySync(jid);
console.log(`Requested message history sync for ${jid}`);
} catch (syncError) {
console.log(`requestMessageHistorySync not available: ${syncError}`);
}
}
On the current version:
console.log(typeof (instance.socket as any).loadMessages); // 'undefined'
console.log(typeof (instance.socket as any).requestMessageHistorySync); // 'undefined'
socket config:
const socket = makeWASocket({
version: [2, 3000, 1029868882],
auth: state,
printQRInTerminal: false,
browser: ["WhatsApp API", "Chrome", "1.0.0"],
connectTimeoutMs: 120_000,
defaultQueryTimeoutMs: 90_000,
keepAliveIntervalMs: 30_000,
retryRequestDelayMs: 250,
qrTimeout: 60_000,
emitOwnEvents: true,
syncFullHistory: true,
shouldSyncHistoryMessage: (msg: any) => {
console.log("History sync notification:", msg.syncType);
return true;
},
logger: this.createLogger(id),
markOnlineOnConnect: true,
patchMessageBeforeSending: (msg: any) => msg,
options: {
headers: {
"User-Agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
Accept:
"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"Cache-Control": "no-cache",
Pragma: "no-cache",
},
},
fireInitQueries: true,
generateHighQualityLinkPreview: false,
linkPreviewImageThumbnailWidth: 192,
transactionOpts: {
maxCommitRetries: 10,
delayBetweenTriesMs: 3000,
},
});
- Connect using QR or saved credentials until connection.update reports connection: "open".
2. Call my syncChatHistory(instanceId, jid) method which contains the loadMessages and requestMessageHistorySync code above.
4. Observe that:
• typeof socket.loadMessages === "undefined"
• typeof socket.requestMessageHistorySync === "undefined"
• No messages are fetched via this path, so manual sync does nothing.
Previously, on an older Baileys version, this approach worked and allowed me to fetch messages and pass them to my handleIncomingMessages function.
now i am using @whiskeysockets/baileys: 7.0.0-rc.6
After connecting a WhatsApp client with Baileys, I’m no longer able to sync historical messages using the approach that previously worked.
I used to rely on two internal methods on the socket:
• socket.loadMessages(jid, limit)
• socket.requestMessageHistorySync(jid)
After updating Baileys, both of these are now undefined on the socket instance, so my sync logic no longer works
My sync code looks like this:
On the current version:
console.log(typeof (instance.socket as any).loadMessages); // 'undefined'console.log(typeof (instance.socket as any).requestMessageHistorySync); // 'undefined'socket config:
2. Call my syncChatHistory(instanceId, jid) method which contains the loadMessages and requestMessageHistorySync code above.
4. Observe that:
• typeof socket.loadMessages === "undefined"
• typeof socket.requestMessageHistorySync === "undefined"
• No messages are fetched via this path, so manual sync does nothing.
Previously, on an older Baileys version, this approach worked and allowed me to fetch messages and pass them to my handleIncomingMessages function.
now i am using @whiskeysockets/baileys: 7.0.0-rc.6