Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(engine): read the Baileys mute end time as milliseconds
Surya7ff0831ff7f8
diff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 6b108aa3b..8fde836be 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -426,9 +426,9 @@ Get active chats for a session, most-recent first (paginated).````archived`, `pinned` and `muted` are the read side of the `chats/archive`, `chats/pin` and-`chats/mute` endpoints. `muted` is a verdict, not an expiry — whatsapp-web.js derives it, while-Baileys reports only a `muteEndTime` whose unit its own type does not fix, so a neutral expiry-would be a units question at every call site.+`chats/mute` endpoints. `muted` is a verdict, not an expiry — whatsapp-web.js derives it from+`Chat.isMuted`, and Baileys carries a `muteEndTime` (epoch milliseconds) the gateway compares+against now. The expiry instant itself is tracked separately in #1473.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"`).diff --git a/openapi.json b/openapi.jsonindex 21bc5ae23..86aa66939 100644--- a/openapi.json+++ b/openapi.json@@ -10259,7 +10259,7 @@},"muted": {"type": "boolean",- "description": "Whether the chat is muted right now, as set via POST /sessions/{sessionId}/chats/mute. A boolean rather than the expiry: whatsapp-web.js derives the verdict itself, and Baileys reports only a muteEndTime whose unit its type does not fix, so an expiry would be a units question at every call site.",+ "description": "Whether the chat is muted right now, as set via POST /sessions/{sessionId}/chats/mute. The verdict rather than the expiry: whatsapp-web.js derives it itself from Chat.isMuted, and Baileys carries a muteEndTime that this gateway compares against now. The expiry instant itself is tracked separately in #1473.","example": false}},diff --git a/src/engine/adapters/baileys-session-store.spec.ts b/src/engine/adapters/baileys-session-store.spec.tsindex f8506f008..5faa75b35 100644--- a/src/engine/adapters/baileys-session-store.spec.ts+++ b/src/engine/adapters/baileys-session-store.spec.ts@@ -64,12 +64,12 @@ describe('BaileysSessionStore', () => {expect(chatFor({}).muted).toBe(false);});- it('reads a second-precision end time too, since the type does not fix the unit', () => {- // `number | Long` says nothing about the unit, and WhatsApp's mute action carries ms while- // the timestamps beside it are seconds. Reading seconds as milliseconds would report every- // mute as expired in 1970.- expect(chatFor({ muteEndTime: Math.floor(Date.now() / 1000) + 3600 }).muted).toBe(true);- expect(chatFor({ muteEndTime: Math.floor(Date.now() / 1000) - 3600 }).muted).toBe(false);+ it('reads the end time as milliseconds, the unit the mute round-trip is measured at', () => {+ // chat-mute.spec.ts records the measurement: a seconds-scale value sent through+ // chatModify({ mute }) left the chat unmuted, because that instant had already passed in+ // 1970. Reading it back the same way keeps the write and the read on one unit — a+ // seconds-scale stamp is an instant in 1970 here too, so it reads as expired.+ expect(chatFor({ muteEndTime: Math.floor(Date.now() / 1000) + 3600 }).muted).toBe(false);});it('accepts a Long, which is what the proto actually hands over', () => {diff --git a/src/engine/adapters/baileys-session-store.ts b/src/engine/adapters/baileys-session-store.tsindex 3f14170d7..e27c834d2 100644--- a/src/engine/adapters/baileys-session-store.ts+++ b/src/engine/adapters/baileys-session-store.ts@@ -398,16 +398,17 @@ export class BaileysSessionStore {/*** Whether a Baileys `muteEndTime` is still in the future.*- * The unit is not fixed by the type (`number | Long`) and WhatsApp's own mute action carries a- * millisecond stamp while the conversation/message timestamps beside it are seconds, so the- * magnitude decides: below 1e12 is a second-precision stamp (1e12 ms is 2001, and no mute- * predates WhatsApp). Guessing wrong in either direction would report a long-expired mute as- * active, or an active one as expired.+ * The stamp is epoch MILLISECONDS, and that is measured rather than inferred: `chat-mute.spec.ts`+ * records that a seconds-scale value sent through `chatModify({ mute })` left the chat unmuted —+ * the instant had already passed in 1970 — while the same instant in milliseconds muted it to+ * the expected minute. `mute-chat.dto.ts` documents the same unit on the way in. Only the proto's+ * unsuffixed `muteEndTime` suggests otherwise, beside fields it does spell `…Ms`, and it is+ * wrong.*/private isMuted(muteEndTime: number | { toNumber(): number } | null | undefined): boolean {- const raw = this.toUnixSeconds(muteEndTime);- if (!raw) return false;- const endMs = raw < 1e12 ? raw * 1000 : raw;+ // toUnixSeconds unwraps Long → number and nothing else; the unit is whatever was passed in.+ const endMs = this.toUnixSeconds(muteEndTime);+ if (!endMs) return false;return endMs > Date.now();}diff --git a/src/engine/interfaces/whatsapp-engine.interface.ts b/src/engine/interfaces/whatsapp-engine.interface.tsindex ed36032f5..619aa6163 100644--- a/src/engine/interfaces/whatsapp-engine.interface.ts+++ b/src/engine/interfaces/whatsapp-engine.interface.ts@@ -498,11 +498,11 @@ export interface ChatSummary {/*** Muted state, as set via `POST /sessions/{sessionId}/chats/mute`.*- * A boolean rather than the expiry the engines hold, deliberately: whatsapp-web.js derives- * `Chat.isMuted` for you, while Baileys reports only a `muteEndTime` whose unit is not fixed by- * its type (`number | Long`), so a neutral expiry would be a units question at every call site.- * "Is this chat muted right now" is the answer a caller needs to label a mute/unmute control,- * and it is the one both engines can give without ambiguity.+ * The verdict rather than the expiry the engines hold, deliberately: "is this chat muted right+ * now" is what a caller needs to label a mute/unmute control, and it is what both engines answer+ * directly — whatsapp-web.js derives `Chat.isMuted` itself, and Baileys carries a `muteEndTime`+ * (epoch milliseconds, per the measurement in `chat-mute.spec.ts`) to compare against now. The+ * expiry instant itself is tracked separately in #1473.*/muted: boolean;}diff --git a/src/modules/session/dto/chat-summary.dto.ts b/src/modules/session/dto/chat-summary.dto.tsindex be0dce692..76cc4ff0d 100644--- a/src/modules/session/dto/chat-summary.dto.ts+++ b/src/modules/session/dto/chat-summary.dto.ts@@ -34,10 +34,10 @@ export class ChatSummaryDto {@ApiProperty({description:- 'Whether the chat is muted right now, as set via POST /sessions/{sessionId}/chats/mute. A ' +- 'boolean rather than the expiry: whatsapp-web.js derives the verdict itself, and Baileys ' +- 'reports only a muteEndTime whose unit its type does not fix, so an expiry would be a units ' +- 'question at every call site.',+ 'Whether the chat is muted right now, as set via POST /sessions/{sessionId}/chats/mute. The ' ++ 'verdict rather than the expiry: whatsapp-web.js derives it itself from Chat.isMuted, and ' ++ 'Baileys carries a muteEndTime that this gateway compares against now. The expiry instant ' ++ 'itself is tracked separately in #1473.',example: false,})muted!: boolean;