Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(engine): surface pinned and muted state on ChatSummary
Suryaa29a31375358
diff --git a/dashboard/src/services/api.ts b/dashboard/src/services/api.tsindex bfcf12446..da48ff774 100644--- a/dashboard/src/services/api.ts+++ b/dashboard/src/services/api.ts@@ -215,6 +215,8 @@ export interface Chat {timestamp: number;lastMessage?: string;archived: boolean;+ pinned: boolean;+ muted: boolean;}// Engine-neutral message types (mirrors the backend's IWhatsAppEngine MessageType). The backenddiff --git a/docs/06-api-specification.md b/docs/06-api-specification.mdindex 1f2bcf4e7..6b108aa3b 100644--- a/docs/06-api-specification.md+++ b/docs/06-api-specification.md@@ -418,11 +418,18 @@ Get active chats for a session, most-recent first (paginated)."unreadCount": 2,"timestamp": 1719306115,"lastMessage": "See you tomorrow",- "archived": false+ "archived": false,+ "pinned": false,+ "muted": false}]```+`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.+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"`).**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-readdiff --git a/openapi.json b/openapi.jsonindex 945cecbf4..21bc5ae23 100644--- a/openapi.json+++ b/openapi.json@@ -10251,6 +10251,16 @@"type": "boolean","description": "Archived state, as set via POST /sessions/{sessionId}/chats/archive.","example": false+ },+ "pinned": {+ "type": "boolean",+ "description": "Pinned state, as set via POST /sessions/{sessionId}/chats/pin.",+ "example": false+ },+ "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.",+ "example": false}},"required": [@@ -10260,7 +10270,9 @@"kind","unreadCount","timestamp",- "archived"+ "archived",+ "pinned",+ "muted"]},"MarkChatReadDto": {diff --git a/sdk/go/types_chat.go b/sdk/go/types_chat.goindex fcda385c0..4666e5fa2 100644--- a/sdk/go/types_chat.go+++ b/sdk/go/types_chat.go@@ -12,6 +12,9 @@ type ChatSummary struct {Timestamp int64 `json:"timestamp"`Kind ChatKind `json:"kind"`Archived bool `json:"archived"`+ Pinned bool `json:"pinned"`+ // Muted reports whether the chat is muted right now, not the expiry behind it.+ Muted bool `json:"muted"`}// SetOwnPresenceRequest is the body for SessionsService.SetOnlinePresence. Available reportsdiff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/ChatSummary.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/ChatSummary.javaindex f501a31d0..c9691a98e 100644--- a/sdk/java/src/main/java/com/rmyndharis/openwa/model/ChatSummary.java+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/ChatSummary.java@@ -15,4 +15,7 @@ public record ChatSummary(String lastMessage,Long timestamp,ChatKind kind,- Boolean archived) {}+ Boolean archived,+ Boolean pinned,+ /** Whether the chat is muted right now, not the expiry behind it. */+ Boolean muted) {}diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.tsindex 861a0325a..96641351e 100644--- a/sdk/javascript/src/types.ts+++ b/sdk/javascript/src/types.ts@@ -944,6 +944,10 @@ export interface ChatSummary {kind: ChatKind;/** Archived state, as set via {@link ChatsResource.archive}. */archived: boolean;+ /** Pinned state, as set via {@link ChatsResource.pin}. */+ pinned: boolean;+ /** Whether the chat is muted right now, as set via {@link ChatsResource.mute}. */+ muted: boolean;}/** Body for {@link SessionsResource.setOnlinePresence}. */diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.pyindex d6e103d46..5a9c995ca 100644--- a/sdk/python/openwa/types.py+++ b/sdk/python/openwa/types.py@@ -889,6 +889,9 @@ class ChatSummary(TypedDict):timestamp: str | intkind: ChatKindarchived: bool+ pinned: bool+ # Whether the chat is muted right now, not the expiry behind it.+ muted: boolclass MarkChatRequest(TypedDict):diff --git a/src/engine/adapters/baileys-session-store.spec.ts b/src/engine/adapters/baileys-session-store.spec.tsindex a4ccb88dd..f8506f008 100644--- a/src/engine/adapters/baileys-session-store.spec.ts+++ b/src/engine/adapters/baileys-session-store.spec.ts@@ -42,6 +42,42 @@ describe('BaileysSessionStore', () => {expect(store.findContact('[email protected]')?.pushName).toBe('Bob');});+ describe('pinned and muted state', () => {+ const chatFor = (over: Record<string, unknown>) => {+ store.upsertChats([{ id: '[email protected]', name: 'Alice', ...over }]);+ return store.listChats()[0];+ };++ it('reads a pin as a flag, though Baileys reports it as an order', () => {+ // proto.IConversation.pinned is a NUMBER — its position among pinned chats, not a boolean.+ expect(chatFor({ pinned: 2 }).pinned).toBe(true);+ expect(chatFor({ pinned: 0 }).pinned).toBe(false);+ expect(chatFor({}).pinned).toBe(false);+ });++ it('treats a mute as active only while its end time is still ahead', () => {+ const inAnHourMs = Date.now() + 60 * 60 * 1000;+ const anHourAgoMs = Date.now() - 60 * 60 * 1000;+ expect(chatFor({ muteEndTime: inAnHourMs }).muted).toBe(true);+ expect(chatFor({ muteEndTime: anHourAgoMs }).muted).toBe(false);+ expect(chatFor({ muteEndTime: 0 }).muted).toBe(false);+ 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('accepts a Long, which is what the proto actually hands over', () => {+ const asLong = { toNumber: () => Date.now() + 60 * 60 * 1000 };+ expect(chatFor({ muteEndTime: asLong }).muted).toBe(true);+ });+ });+it('records the newest message per chat and surfaces it in getChats', () => {store.upsertChats([{ id: '[email protected]', name: 'Alice', unreadCount: 2 }]);store.recordMessage({@@ -65,6 +101,8 @@ describe('BaileysSessionStore', () => {timestamp: 200,lastMessage: 'newest',archived: false,+ pinned: false,+ muted: false,},]);expect(store.lastMessage('[email protected]')).toEqual({diff --git a/src/engine/adapters/baileys-session-store.ts b/src/engine/adapters/baileys-session-store.tsindex 6106a1aa2..3f14170d7 100644--- a/src/engine/adapters/baileys-session-store.ts+++ b/src/engine/adapters/baileys-session-store.ts@@ -389,9 +389,28 @@ export class BaileysSessionStore {timestamp: last?.timestamp ?? this.toUnixSeconds(c.conversationTimestamp),lastMessage: last?.text,archived: c.archived ?? false,+ // Baileys reports a pin as an ORDER, not a flag — 0/absent means unpinned.+ pinned: Boolean(c.pinned),+ muted: this.isMuted(c.muteEndTime),};}+ /**+ * 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.+ */+ 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;+ return endMs > Date.now();+ }+/*** Best-known display name for a chat id when Baileys gave the chat no title (#369). Prefers the saved* contact name, then verifiedName, then pushName (`notify`); for a @lid chat it also tries the contactdiff --git a/src/engine/adapters/baileys.adapter.spec.ts b/src/engine/adapters/baileys.adapter.spec.tsindex 5411f145a..894f56ffb 100644--- a/src/engine/adapters/baileys.adapter.spec.ts+++ b/src/engine/adapters/baileys.adapter.spec.ts@@ -4263,6 +4263,8 @@ describe('BaileysAdapter contact + chat reads', () => {timestamp: 1700000010,lastMessage: 'hi',archived: false,+ pinned: false,+ muted: false,});});diff --git a/src/engine/adapters/wwebjs-chats.ts b/src/engine/adapters/wwebjs-chats.tsindex 616935f7f..079260491 100644--- a/src/engine/adapters/wwebjs-chats.ts+++ b/src/engine/adapters/wwebjs-chats.ts@@ -61,6 +61,9 @@ export class WwebjsChats {// A location message's body is the base64 map thumbnail; don't surface it as the chat preview.lastMessage: chat.lastMessage?.type === MessageTypes.LOCATION ? '📍' : chat.lastMessage?.body || undefined,archived: Boolean(chat.archived),+ pinned: Boolean(chat.pinned),+ // Chat.isMuted is already the current verdict; muteExpiration is the raw stamp behind it.+ muted: Boolean(chat.isMuted),});}diff --git a/src/engine/adapters/wwebjs-labels.ts b/src/engine/adapters/wwebjs-labels.tsindex 5bb946bec..52b60ebf4 100644--- a/src/engine/adapters/wwebjs-labels.ts+++ b/src/engine/adapters/wwebjs-labels.ts@@ -75,6 +75,8 @@ export class WwebjsLabels {unreadCount: chat.unreadCount || 0,timestamp: chat.timestamp || 0,archived: Boolean(chat.archived),+ pinned: Boolean(chat.pinned),+ muted: Boolean(chat.isMuted),});}return summaries;diff --git a/src/engine/interfaces/whatsapp-engine.interface.ts b/src/engine/interfaces/whatsapp-engine.interface.tsindex c04221044..ed36032f5 100644--- a/src/engine/interfaces/whatsapp-engine.interface.ts+++ b/src/engine/interfaces/whatsapp-engine.interface.ts@@ -493,6 +493,18 @@ export interface ChatSummary {lastMessage?: string;/** Archived state, as set via `POST /sessions/{sessionId}/chats/archive`. */archived: boolean;+ /** Pinned state, as set via `POST /sessions/{sessionId}/chats/pin`. */+ pinned: boolean;+ /**+ * 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.+ */+ muted: boolean;}/**diff --git a/src/engine/types/whatsapp-web-js.types.ts b/src/engine/types/whatsapp-web-js.types.tsindex ae48821d1..5a90979eb 100644--- a/src/engine/types/whatsapp-web-js.types.ts+++ b/src/engine/types/whatsapp-web-js.types.ts@@ -139,6 +139,8 @@ export interface BusinessClient extends Omit<unreadCount?: number;timestamp?: number;archived?: boolean;+ pinned?: boolean;+ isMuted?: boolean;}| undefined>diff --git a/src/modules/session/dto/chat-summary.dto.ts b/src/modules/session/dto/chat-summary.dto.tsindex 0abcadaf7..be0dce692 100644--- a/src/modules/session/dto/chat-summary.dto.ts+++ b/src/modules/session/dto/chat-summary.dto.ts@@ -28,4 +28,17 @@ export class ChatSummaryDto {@ApiProperty({ description: 'Archived state, as set via POST /sessions/{sessionId}/chats/archive.', example: false })archived!: boolean;++ @ApiProperty({ description: 'Pinned state, as set via POST /sessions/{sessionId}/chats/pin.', example: false })+ pinned!: boolean;++ @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.',+ example: false,+ })+ muted!: boolean;}