You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[BUG] chats.update / initial history sync discard the archived flag before it reaches webhooks or the database #2743
When a chat is archived/unarchived on the phone (or any linked device), Baileys emits the change via chats.update with an archived: true/false field. Evolution's chats.update handler in whatsapp.baileys.service.ts (WHATSAPP-BAILEYS integration) discards every field except remoteJid before forwarding to the webhook or writing to the DB:
The messaging-history.set handler (emits chats.set) does the same trim, and additionally only forwards chats not already in the Chat table — so even a fresh reconnect can't backfill archive state for chats Evolution already knows about.
The Chat Postgres table also has no archived column at all:
Table "public.Chat"
id | remoteJid | labels | createdAt | updatedAt | instanceId | name | unreadMessages
So there is currently no way for an integrator to learn a chat's real archived state via webhook, DB, or GET /chat/findChats/:instance — it's dropped at the earliest point in Evolution's own pipeline.
🔄 Steps to Reproduce
Connect an instance (WHATSAPP-BAILEYS) with the chats.update webhook enabled.
Archive (or unarchive) any chat directly on the linked phone.
Inspect the delivered chats.update webhook payload.
Check the Chat row for that remoteJid via GET /chat/findChats/:instance or Postgres directly.
✅ Expected Behavior
chats.update carries the chat's current archived boolean, it's persisted on the Chat row, and findChats returns it — so integrators can mirror the phone's real archived list instead of maintaining a local-only flag.
❌ Actual Behavior
chats.update/chats.set payloads only ever contain {remoteJid, instanceId[, name]}. archived is silently discarded.
🌍 Environment
OS: Ubuntu (Docker host)
Evolution API version: 2.3.7
Integration: WHATSAPP-BAILEYS
Database: PostgreSQL 13
📝 Additional Context / Proposed Fix
Sketch of a fix, for whoever picks this up:
Add archived Boolean @default(false) to the Chat Prisma model (migration).
In chats.update, forward archived: chat.archived in the webhook payload and include it in the chat.updateMany write.
In messaging-history.set, same field addition; consider also letting already-known chats' archived/pinned/muteEndTime refresh on reconnect, since today only brand-new chats get forwarded at all.
Confirm findChats selects/returns the new column once it exists.
Related: #2495 looks like a different symptom in the same area (write-side archiveChat endpoint erroring) — this is the read side: archive state never reaching the integrator in the first place.
The same trim in chats.update also drops unreadCount (and markedAsUnread), so the fix proposed here could cover unread state at the same time.
On 2.3.7 (whatsapp.baileys.service.ts, chatHandle['chats.update'], ~line 777), the handler maps each update to { remoteJid, instanceId } before the webhook and the DB write. When the owner reads a chat on the phone, WhatsApp syncs that as an app-state chats.update carrying unreadCount: 0. That is the only reliable "read on the phone" signal Baileys exposes, and Evolution discards it, the same way it discards archived.
What Evolution uses instead isn't a substitute:
messages.update (~line 1715) writes unreadMessages: 0 onto the chat row whenever any message in that chat gets a status update, and re-emits chats.upsert with that 0.
updateChatUnreadMessages() (~line 4759) recounts unread as incoming Message rows still at DELIVERY_ACK. History-synced messages rarely receive a later read status, so that count drifts far from the phone. On one account whose phone showed no unread badges, counting this way gave 651 unread.
Separately, updateChatUnreadMessages() looks the chat up with chat.findFirst({ where: { remoteJid } }), without instanceId. On a server with several instances that share a contact or group, it can write one instance's count onto another instance's Chat row. That looks like its own small bug, so flagging it here in case whoever touches this code wants to fix it at the same time.
So the sketch above could be extended by one field: forward unreadCount (and archived, pinned, markedAsUnread) in the chats.update / chats.set payloads, and when unreadCount is present, persist it to Chat.unreadMessages and prefer it over the status-based recount. #2561 already fixes the history-sync half of unread (Conversation.unreadCount in messaging-history.set); this is the live half.
For anyone looking for a workaround in the meantime: none that we found through the API. Our integration stopped showing unread counts for WhatsApp rather than show wrong ones.
Activity
hugoalves-dev commentedon Oct 16, 2026
Hi! I was think at using the EvolutionAPI, but that bug is a problem for that I want to implement. It was solved or there are some workaround?
ju-li commentedon Nov 5, 2026
The same trim in
chats.updatealso dropsunreadCount(andmarkedAsUnread), so the fix proposed here could cover unread state at the same time.On 2.3.7 (
whatsapp.baileys.service.ts,chatHandle['chats.update'], ~line 777), the handler maps each update to{ remoteJid, instanceId }before the webhook and the DB write. When the owner reads a chat on the phone, WhatsApp syncs that as an app-statechats.updatecarryingunreadCount: 0. That is the only reliable "read on the phone" signal Baileys exposes, and Evolution discards it, the same way it discardsarchived.What Evolution uses instead isn't a substitute:
messages.update(~line 1715) writesunreadMessages: 0onto the chat row whenever any message in that chat gets a status update, and re-emitschats.upsertwith that 0.updateChatUnreadMessages()(~line 4759) recounts unread as incomingMessagerows still atDELIVERY_ACK. History-synced messages rarely receive a later read status, so that count drifts far from the phone. On one account whose phone showed no unread badges, counting this way gave 651 unread.updateChatUnreadMessages()looks the chat up withchat.findFirst({ where: { remoteJid } }), withoutinstanceId. On a server with several instances that share a contact or group, it can write one instance's count onto another instance'sChatrow. That looks like its own small bug, so flagging it here in case whoever touches this code wants to fix it at the same time.So the sketch above could be extended by one field: forward
unreadCount(andarchived,pinned,markedAsUnread) in thechats.update/chats.setpayloads, and whenunreadCountis present, persist it toChat.unreadMessagesand prefer it over the status-based recount. #2561 already fixes the history-sync half of unread (Conversation.unreadCountinmessaging-history.set); this is the live half.For anyone looking for a workaround in the meantime: none that we found through the API. Our integration stopped showing unread counts for WhatsApp rather than show wrong ones.