Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(sdk): expose the chat pin and mute routes in all five SDKs
Yudhi Armyndharis16916062775e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a6d2dc873..87f0528db 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Added+- The JavaScript, Python, PHP, Go and Java SDKs expose `POST /sessions/:id/chats/pin` and `chats/mute`, which the gateway has published since v0.15.0 with no client counterpart. `muteUntil` is epoch milliseconds and `null` unmutes; both are required, since an omitted value reads as either.- `POST /sessions/:sessionId/channels/:channelId/owner/transfer` hands a channel to a new owner on the Baileys engine; it is irreversible, and the account cannot take the channel back. The whatsapp-web.js engine answers `501`.- `POST /sessions/:sessionId/channels/:channelId/admins/demote` demotes a channel admin back to a subscriber on the Baileys engine; neither library has a promote counterpart, so promote from the WhatsApp app. The whatsapp-web.js engine answers `501`.- `POST /sessions/:id/chats/pin` pins a chat to the top of the list or unpins it, on both engines; `success: false` reports WhatsApp's three-pin cap, which only the whatsapp-web.js engine can observe.diff --git a/docs/18-sdk-design.md b/docs/18-sdk-design.mdindex 100d30223..8cef10c15 100644--- a/docs/18-sdk-design.md+++ b/docs/18-sdk-design.md@@ -33,7 +33,7 @@ All five SDKs expose the same fluent surface:| `contacts` | list, get, check, profilePicture, profilePictures, phone, upsert, delete, block, unblock, listBlocked || `groups` | list, get, create, joinInfo, joinGroup, add/remove/promote/demoteParticipants, setSubject, setDescription, getGroupSettings, updateGroupSettings, leave, getPicture, setPicture, deletePicture, inviteCode, revokeInviteCode, getMembershipRequests, approveMembershipRequests, rejectMembershipRequests || `webhooks` | list, listAll, deliveryFailures, get, create, update, delete, test |-| `chats` | list, subscribePresence, getPresence, markRead, markUnread, archive, clearMessages, delete, sendState |+| `chats` | list, subscribePresence, getPresence, markRead, markUnread, archive, pin, mute, clearMessages, delete, sendState || `labels` | list, get, chats, upsert, delete, forChat, addToChat, removeFromChat _(WhatsApp Business)_ || `channels` | list, get, messages, create, delete, mute, subscribe, unsubscribe _(Newsletters)_ || `catalog` | info, products, product, sendProduct, sendCatalog _(WhatsApp Business)_ |@@ -227,6 +227,8 @@ Media bodies share the `SendMediaRequest` shape: `{ chatId, url? | base64?, mime| `markRead` | `markRead(sessionId, body)` | Mark a chat as read/seen. **OPERATOR** || `markUnread` | `markUnread(sessionId, body)` | Mark a chat as unread. **OPERATOR** || `archive` | `archive(sessionId, body)` | Archive or unarchive a chat. `success: false` means the engine declined. **OPERATOR** |+| `pin` | `pin(sessionId, body)` | Pin a chat to the top of the list, or unpin it. `success: false` means WhatsApp declined — three pins maximum. **OPERATOR** |+| `mute` | `mute(sessionId, body)` | Mute a chat until an absolute epoch-MILLISECONDS timestamp, or unmute with `null`. **OPERATOR** || `clearMessages` | `clearMessages(sessionId, chatId)` | Delete every message in a chat, keeping the chat itself. **OPERATOR** || `delete` | `delete(sessionId, body)` | Delete a chat from the chat list. **OPERATOR** || `sendState` | `sendState(sessionId, body)` | Send a chat presence state (typing/recording/paused). **OPERATOR** |@@ -591,6 +593,8 @@ Resources are accessed as properties on the client (e.g. `client.messages`). All| `mark_read` | `mark_read(session_id, body) -> SuccessResult` | Mark a chat as read. **OPERATOR** || `mark_unread` | `mark_unread(session_id, body) -> SuccessResult` | Mark a chat as unread. **OPERATOR** || `archive` | `archive(session_id, body) -> SuccessResult` | Archive or unarchive a chat. `success: false` means the engine declined. **OPERATOR** |+| `pin` | `pin(session_id, body) -> SuccessResult` | Pin a chat to the top of the list, or unpin it. `success: false` means WhatsApp declined — three pins maximum. **OPERATOR** |+| `mute` | `mute(session_id, body) -> SuccessResult` | Mute a chat until an absolute epoch-MILLISECONDS timestamp, or unmute with `null`. **OPERATOR** || `clear_messages` | `clear_messages(session_id, chat_id) -> SuccessResult` | Delete every message in a chat, keeping the chat itself. **OPERATOR** || `delete` | `delete(session_id, body) -> SuccessResult` | Delete a chat. **OPERATOR** || `send_state` | `send_state(session_id, body) -> SuccessResult` | Send a typing/recording chat state. **OPERATOR** |@@ -928,6 +932,8 @@ All payloads are associative arrays; all listed methods are synchronous and retu| `markRead` | `markRead(string $sessionId, array $body): array` | Mark chat(s) read. **OPERATOR** || `markUnread` | `markUnread(string $sessionId, array $body): array` | Mark chat(s) unread. **OPERATOR** || `archive` | `archive(string $sessionId, array $body): array` | Archive or unarchive a chat. `success: false` means the engine declined. **OPERATOR** |+| `pin` | `pin(string $sessionId, array $body): array` | Pin a chat to the top of the list, or unpin it. `success: false` means WhatsApp declined — three pins maximum. **OPERATOR** |+| `mute` | `mute(string $sessionId, array $body): array` | Mute a chat until an absolute epoch-MILLISECONDS timestamp, or unmute with `null`. **OPERATOR** || `clearMessages` | `clearMessages(string $sessionId, string $chatId): array` | Delete every message in a chat, keeping the chat itself. **OPERATOR** || `delete` | `delete(string $sessionId, array $body): array` | Delete chat(s). **OPERATOR** || `sendState` | `sendState(string $sessionId, array $body): array` | Send a typing/recording state. **OPERATOR** |diff --git a/sdk/README.md b/sdk/README.mdindex 91b121cc8..520a692af 100644--- a/sdk/README.md+++ b/sdk/README.md@@ -29,7 +29,7 @@ All five SDKs expose the same fluent resource surface:| `contacts` | list, get, check, profilePicture, profilePictures, phone, upsert, delete, block, unblock, listBlocked || `groups` | list, get, create, joinGroup, joinInfo, add/remove/promote/demoteParticipants, setSubject, setDescription, get/updateGroupSettings, leave, getPicture, setPicture, deletePicture, inviteCode, revokeInviteCode, getMembershipRequests, approveMembershipRequests, rejectMembershipRequests || `webhooks` | list, listAll, deliveryFailures, get, create, update, delete, test |-| `chats` | list, markRead, markUnread, archive, clearMessages, delete, sendState, subscribePresence, getPresence |+| `chats` | list, markRead, markUnread, archive, pin, mute, clearMessages, delete, sendState, subscribePresence, getPresence || `labels` | list, get, chats, forChat, upsert, delete, addToChat, removeFromChat _(WhatsApp Business)_ || `channels` | list, get, messages, create, delete, mute, subscribe, unsubscribe _(Newsletters)_ || `catalog` | info, products, product, sendProduct, sendCatalog _(WhatsApp Business)_ |diff --git a/sdk/go/chats.go b/sdk/go/chats.goindex 15681fd7f..146dbe8f1 100644--- a/sdk/go/chats.go+++ b/sdk/go/chats.go@@ -61,6 +61,22 @@ func (s *ChatsService) Archive(ctx context.Context, sessionID string, body Archireturn s.post(ctx, sessionID, "/archive", body)}+// Pin pins a chat to the top of the list, or unpins it. A false Success means+// WhatsApp declined — an account may pin only three chats at a time.+func (s *ChatsService) Pin(ctx context.Context, sessionID string, body PinChatRequest) (*SuccessResult, error) {+ return s.post(ctx, sessionID, "/pin", body)+}++// Mute mutes a chat until an absolute timestamp, or unmutes it when+// body.MuteUntil is nil.+//+// MuteUntil is epoch MILLISECONDS. Passing seconds points at an instant in+// 1970, so the mute expires the moment it is set while the call still succeeds+// — nothing in the response distinguishes that from a mute that took effect.+func (s *ChatsService) Mute(ctx context.Context, sessionID string, body MuteChatRequest) (*SuccessResult, error) {+ return s.post(ctx, sessionID, "/mute", body)+}+// ClearMessages deletes every message in a chat, keeping the chat itself. A// false Success means the engine declined — an unknown chat, or on Baileys a// chat with no known history.diff --git a/sdk/go/mute_chat_test.go b/sdk/go/mute_chat_test.gonew file mode 100644index 000000000..0a3ddc20e--- /dev/null+++ b/sdk/go/mute_chat_test.go@@ -0,0 +1,35 @@+package openwa++import (+ "encoding/json"+ "strings"+ "testing"+)++// Unmuting is a nil MuteUntil, and the route requires the key to be present: with `omitempty` the+// field would vanish from the body and the request would be rejected, so the one thing nil should+// express could not be. An omitted value is also ambiguous in a way null is not — unmute now and+// mute indefinitely are opposite readings of the same absence.+func TestMuteChatRequestEncodesNilMuteUntilAsExplicitNull(t *testing.T) {+ body, err := json.Marshal(MuteChatRequest{ChatID: "[email protected]"})+ if err != nil {+ t.Fatalf("marshal: %v", err)+ }+ if !strings.Contains(string(body), `"muteUntil":null`) {+ t.Errorf("nil MuteUntil must serialise as an explicit null, got %s", body)+ }+}++// The timestamp is epoch MILLISECONDS. A value rescaled to seconds points at an instant in 1970, so+// the mute expires immediately while the call still answers 200 — the wrong unit is invisible in the+// response and only observable on the wire.+func TestMuteChatRequestSendsEpochMillisecondsUnchanged(t *testing.T) {+ until := int64(1893456000000)+ body, err := json.Marshal(MuteChatRequest{ChatID: "[email protected]", MuteUntil: &until})+ if err != nil {+ t.Fatalf("marshal: %v", err)+ }+ if !strings.Contains(string(body), `"muteUntil":1893456000000`) {+ t.Errorf("MuteUntil must reach the wire unscaled, got %s", body)+ }+}diff --git a/sdk/go/routing_test.go b/sdk/go/routing_test.goindex 473aceff0..32073e91c 100644--- a/sdk/go/routing_test.go+++ b/sdk/go/routing_test.go@@ -106,6 +106,8 @@ func TestRouting(t *testing.T) {{"Chats.MarkUnread", func(c *Client) { c.Chats.MarkUnread(ctx, "s1", MarkChatRequest{}) }, "POST", "/api/sessions/s1/chats/unread"},{"Chats.ClearMessages", func(c *Client) { c.Chats.ClearMessages(ctx, "s1", "c1") }, "DELETE", "/api/sessions/s1/chats/c1/messages"},{"Chats.Archive", func(c *Client) { c.Chats.Archive(ctx, "s1", ArchiveChatRequest{}) }, "POST", "/api/sessions/s1/chats/archive"},+ {"Chats.Pin", func(c *Client) { c.Chats.Pin(ctx, "s1", PinChatRequest{}) }, "POST", "/api/sessions/s1/chats/pin"},+ {"Chats.Mute", func(c *Client) { c.Chats.Mute(ctx, "s1", MuteChatRequest{}) }, "POST", "/api/sessions/s1/chats/mute"},{"Chats.Delete", func(c *Client) { c.Chats.Delete(ctx, "s1", DeleteChatRequest{}) }, "POST", "/api/sessions/s1/chats/delete"},{"Chats.SendState", func(c *Client) { c.Chats.SendState(ctx, "s1", SendChatStateRequest{}) }, "POST", "/api/sessions/s1/chats/typing"},diff --git a/sdk/go/types_chat.go b/sdk/go/types_chat.goindex 2d3ef2b15..e62b25c72 100644--- a/sdk/go/types_chat.go+++ b/sdk/go/types_chat.go@@ -41,6 +41,26 @@ type ArchiveChatRequest struct {Archive bool `json:"archive"`}+// PinChatRequest pins a chat to the top of the list, or unpins it.+type PinChatRequest struct {+ ChatID string `json:"chatId"`+ Pin bool `json:"pin"`+}++// MuteChatRequest mutes a chat until an absolute timestamp, or unmutes it.+type MuteChatRequest struct {+ ChatID string `json:"chatId"`+ // MuteUntil is an absolute epoch-MILLISECONDS timestamp, or nil to unmute now.+ //+ // Milliseconds, not seconds: a seconds-scale value is an instant in 1970, so the mute expires+ // the moment it is set while the request still answers 200.+ //+ // Deliberately no omitempty. The route requires the key, so a nil MuteUntil has to reach it as+ // an explicit null — omitting it is rejected, and the two readings of an absent value, unmute+ // now and mute indefinitely, are opposites.+ MuteUntil *int64 `json:"muteUntil"`+}+// ListChatsQuery paginates the chat list.type ListChatsQuery struct {Limit *intdiff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java b/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.javaindex 21f42a55c..79f657272 100644--- a/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java@@ -9,6 +9,7 @@ import com.rmyndharis.openwa.http.BinaryResponse;import com.rmyndharis.openwa.http.DefaultHttpTransport;import com.rmyndharis.openwa.http.Http;import com.rmyndharis.openwa.http.HttpMethod;+import com.rmyndharis.openwa.model.MuteChatRequest;import com.rmyndharis.openwa.model.UpdateSessionConfigRequest;import com.rmyndharis.openwa.model.UpdateSessionConfigRequestSerializer;import com.rmyndharis.openwa.http.HttpRequestData;@@ -51,12 +52,13 @@ import java.util.Map;public final class OpenWAClient {private final Gson gson = new Gson();- // Used for ONE body type. Emitting an explicit null needs two things that pull in opposite- // directions: a serializer that decides WHICH keys appear, and serializeNulls() so the ones it- // chose survive the writer — Gson drops JsonNull members otherwise, even from a JsonObject the- // serializer already built. Applying serializeNulls() to the shared instance instead would turn- // every unset field of every other body into an explicit null, which this very route reads as- // "reset to default": a far worse bug than the one it fixes.+ // Used for the two body types listed in bodySerializer(), never the shared default. Emitting an+ // explicit null needs two things that pull in opposite directions: a serializer that decides+ // WHICH keys appear, and serializeNulls() so the ones it chose survive the writer — Gson drops+ // JsonNull members otherwise, even from a JsonObject the serializer already built. Applying+ // serializeNulls() to the shared instance instead would turn every unset field of every other+ // body into an explicit null, which the session-config route reads as "reset to default": a far+ // worse bug than the one it fixes.private final Gson nullEmittingGson = new GsonBuilder().serializeNulls().registerTypeAdapter(UpdateSessionConfigRequest.class, new UpdateSessionConfigRequestSerializer())@@ -180,9 +182,17 @@ public final class OpenWAClient {return body == null ? "" : new String(body, StandardCharsets.UTF_8);}- /** The session-config body is the only one that must be able to emit an explicit null. */+ /**+ * The bodies that must be able to emit an explicit null.+ *+ * Gson drops null members by default, so for these two a null field would leave the request+ * without the key at all — which is not a weaker version of the request, it is a different one.+ * {@link MuteChatRequest} is safe to route here despite the warning on {@code nullEmittingGson}+ * because both of its fields are required: it has no optional field that an explicit null could+ * turn into an unintended "reset to default".+ */private Gson bodySerializer(Object body) {- return body instanceof UpdateSessionConfigRequest ? nullEmittingGson : gson;+ return body instanceof UpdateSessionConfigRequest || body instanceof MuteChatRequest ? nullEmittingGson : gson;}private HttpResponseData execute(HttpMethod method, String path, Object query, Object body) {diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/MuteChatRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/MuteChatRequest.javanew file mode 100644index 000000000..59f42d29f--- /dev/null+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/MuteChatRequest.java@@ -0,0 +1,40 @@+package com.rmyndharis.openwa.model;++/**+ * Request body for muting a chat until an absolute timestamp, or unmuting it.+ *+ * <p>This body is serialized by the client's null-emitting Gson. A null {@code muteUntil} is the+ * unmute signal and has to reach the wire as an explicit null — Gson's default behaviour would drop+ * the key entirely, which the route rejects rather than reading as an unmute.+ */+public record MuteChatRequest(String chatId, Long muteUntil) {+ public static Builder builder() {+ return new Builder();+ }++ public static final class Builder {+ private String chatId;+ private Long muteUntil;++ public Builder chatId(String v) {+ this.chatId = v;+ return this;+ }++ /**+ * Absolute epoch MILLISECONDS at which the mute expires, or null to unmute now.+ *+ * <p>Milliseconds, not seconds: a seconds-scale value is an instant in 1970, so the mute+ * expires the moment it is set while the request still answers 200, and nothing in the+ * response says otherwise.+ */+ public Builder muteUntil(Long v) {+ this.muteUntil = v;+ return this;+ }++ public MuteChatRequest build() {+ return new MuteChatRequest(chatId, muteUntil);+ }+ }+}diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/PinChatRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/PinChatRequest.javanew file mode 100644index 000000000..05d8ac82f--- /dev/null+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/PinChatRequest.java@@ -0,0 +1,28 @@+package com.rmyndharis.openwa.model;++/** Request body for pinning a chat to the top of the list, or unpinning it. */+public record PinChatRequest(String chatId, Boolean pin) {+ public static Builder builder() {+ return new Builder();+ }++ public static final class Builder {+ private String chatId;+ private Boolean pin;++ public Builder chatId(String v) {+ this.chatId = v;+ return this;+ }++ /** true to pin the chat to the top of the list, false to unpin it. */+ public Builder pin(Boolean v) {+ this.pin = v;+ return this;+ }++ public PinChatRequest build() {+ return new PinChatRequest(chatId, pin);+ }+ }+}diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ChatsResource.java b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ChatsResource.javaindex 285ba75ad..ea910e54a 100644--- a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ChatsResource.java+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ChatsResource.java@@ -10,6 +10,8 @@ import com.rmyndharis.openwa.model.ChatSummary;import com.rmyndharis.openwa.model.DeleteChatRequest;import com.rmyndharis.openwa.model.ListChatsQuery;import com.rmyndharis.openwa.model.MarkChatRequest;+import com.rmyndharis.openwa.model.MuteChatRequest;+import com.rmyndharis.openwa.model.PinChatRequest;import com.rmyndharis.openwa.model.SendChatStateRequest;import com.rmyndharis.openwa.model.SuccessResult;import java.util.List;@@ -100,6 +102,27 @@ public final class ChatsResource {HttpMethod.POST, "/api/sessions/" + encodeSegment(sessionId) + "/chats/archive", null, body, SuccessResult.class);}+ /**+ * Pin a chat to the top of the list, or unpin it. A false success means WhatsApp declined —+ * an account may pin only three chats at a time.+ */+ public SuccessResult pin(String sessionId, PinChatRequest body) {+ return client.request(+ HttpMethod.POST, "/api/sessions/" + encodeSegment(sessionId) + "/chats/pin", null, body, SuccessResult.class);+ }++ /**+ * Mute a chat until an absolute timestamp, or unmute it with a null {@code muteUntil}.+ *+ * <p>{@code muteUntil} is epoch MILLISECONDS. Passing seconds points at an instant in 1970, so+ * the mute expires the moment it is set while the call still succeeds — nothing in the response+ * distinguishes that from a mute that took effect.+ */+ public SuccessResult mute(String sessionId, MuteChatRequest body) {+ return client.request(+ HttpMethod.POST, "/api/sessions/" + encodeSegment(sessionId) + "/chats/mute", null, body, SuccessResult.class);+ }+/** Delete a chat from the chat list. */public SuccessResult delete(String sessionId, DeleteChatRequest body) {return client.request(diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ChatsResourceTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ChatsResourceTest.javaindex 86d5df896..979ec295e 100644--- a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ChatsResourceTest.java+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ChatsResourceTest.java@@ -9,6 +9,8 @@ import com.rmyndharis.openwa.http.HttpMethod;import com.rmyndharis.openwa.model.ChatState;import com.rmyndharis.openwa.model.ArchiveChatRequest;import com.rmyndharis.openwa.model.DeleteChatRequest;+import com.rmyndharis.openwa.model.MuteChatRequest;+import com.rmyndharis.openwa.model.PinChatRequest;import com.rmyndharis.openwa.model.ListChatsQuery;import com.rmyndharis.openwa.model.MarkChatRequest;import com.rmyndharis.openwa.model.SendChatStateRequest;@@ -78,6 +80,45 @@ class ChatsResourceTest {assertTrue(tx.lastRequest().body().contains("[email protected]"));}+ @Test+ void pinSendsBody() {+ tx.respond(200, "{\"success\":true}");+ client.chats.pin("s", PinChatRequest.builder().chatId("[email protected]").pin(true).build());+ assertEquals("http://h/api/sessions/s/chats/pin", tx.lastRequest().url());+ assertEquals(HttpMethod.POST, tx.lastRequest().method());+ assertTrue(tx.lastRequest().body().contains("\"pin\":true"));+ }++ /**+ * The timestamp is epoch MILLISECONDS and must reach the wire unscaled. A value rescaled to+ * seconds is an instant in 1970, so the mute expires immediately while the call still answers+ * 200 — the wrong unit is invisible in the response.+ */+ @Test+ void muteSendsEpochMillisecondsUnchanged() {+ tx.respond(200, "{\"success\":true}");+ client.chats.mute("s", MuteChatRequest.builder().chatId("[email protected]").muteUntil(1893456000000L).build());+ assertEquals("http://h/api/sessions/s/chats/mute", tx.lastRequest().url());+ assertEquals(HttpMethod.POST, tx.lastRequest().method());+ assertTrue(tx.lastRequest().body().contains("\"muteUntil\":1893456000000"));+ }++ /**+ * Unmuting is a null muteUntil, and the route requires the key. Gson drops null members by+ * default, so without the client routing this body through its null-emitting serializer the key+ * would vanish and the request would be rejected — the one thing null should express could not+ * be. An omitted value is ambiguous in a way null is not: unmute now and mute indefinitely are+ * opposite readings of the same absence.+ */+ @Test+ void muteSendsExplicitNullToUnmute() {+ tx.respond(200, "{\"success\":true}");+ client.chats.mute("s", MuteChatRequest.builder().chatId("[email protected]").build());+ assertTrue(+ tx.lastRequest().body().contains("\"muteUntil\":null"),+ "null muteUntil must survive as an explicit null, got " + tx.lastRequest().body());+ }+@Testvoid deleteSendsBody() {tx.respond(200, "{\"success\":true}");diff --git a/sdk/javascript/src/resources/chats.ts b/sdk/javascript/src/resources/chats.tsindex 256e49ccd..bece30025 100644--- a/sdk/javascript/src/resources/chats.ts+++ b/sdk/javascript/src/resources/chats.ts@@ -12,6 +12,8 @@ import { encodeSegment } from '../http.js';import type { OpenWAClient } from '../client.js';import type {ArchiveChatRequest,+ PinChatRequest,+ MuteChatRequest,ChatSummary,DeleteChatRequest,MarkChatRequest,@@ -94,6 +96,33 @@ export class ChatsResource {});}+ /**+ * Pin a chat to the top of the list, or unpin it. `success: false` means WhatsApp declined —+ * an account may pin only three chats at a time.+ */+ pin(sessionId: string, body: PinChatRequest): Promise<SuccessResult> {+ return this.client.request<SuccessResult>({+ method: 'POST',+ path: `/api/sessions/${encodeSegment(sessionId)}/chats/pin`,+ body,+ });+ }++ /**+ * Mute a chat until an absolute timestamp, or unmute it with `muteUntil: null`.+ *+ * `muteUntil` is epoch **milliseconds**. Passing seconds points at an instant in 1970, so the+ * mute expires the moment it is set while the call still succeeds — nothing in the response+ * distinguishes that from a mute that took effect.+ */+ mute(sessionId: string, body: MuteChatRequest): Promise<SuccessResult> {+ return this.client.request<SuccessResult>({+ method: 'POST',+ path: `/api/sessions/${encodeSegment(sessionId)}/chats/mute`,+ body,+ });+ }+/*** Delete every message in a chat, keeping the chat itself. `success: false` means the engine* declined — an unknown chat, or on Baileys a chat with no known history.diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.tsindex f64f986d9..42f8fb4a7 100644--- a/sdk/javascript/src/types.ts+++ b/sdk/javascript/src/types.ts@@ -341,6 +341,25 @@ export interface ArchiveChatRequest {archive: boolean;}+export interface PinChatRequest {+ chatId: Jid;+ /** true to pin the chat to the top of the list, false to unpin it. */+ pin: boolean;+}++export interface MuteChatRequest {+ chatId: Jid;+ /**+ * Absolute epoch **milliseconds** at which the mute expires, or `null` to unmute now.+ *+ * Milliseconds, not seconds — a seconds-scale value is an instant in 1970, so the mute expires+ * immediately while the request still answers 200 and nothing in the response says otherwise.+ * Required rather than optional because the two readings of an omitted value, unmute now and mute+ * indefinitely, are opposites.+ */+ muteUntil: number | null;+}+export interface VotePollRequest {chatId: Jid;/** The poll creation message to vote on. */diff --git a/sdk/javascript/test/resources.test.ts b/sdk/javascript/test/resources.test.tsindex efeedaed2..6bdf4603b 100644--- a/sdk/javascript/test/resources.test.ts+++ b/sdk/javascript/test/resources.test.ts@@ -400,6 +400,39 @@ describe('ChatsResource.archive', () => {});});+describe('ChatsResource.pin', () => {+ it('posts chatId and the pin flag', async () => {+ const t = new MockTransport().on('POST', /\/chats\/pin$/, { body: { success: true } });+ await client(t).chats.pin('s', { chatId: '[email protected]', pin: true });+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s/chats/pin');+ expect(t.lastCall!.body).toEqual({ chatId: '[email protected]', pin: true });+ });++ it('reports the three-pin refusal rather than throwing', async () => {+ const t = new MockTransport().on('POST', /\/chats\/pin$/, { body: { success: false } });+ await expect(client(t).chats.pin('s', { chatId: '[email protected]', pin: true })).resolves.toEqual({ success: false });+ });+});++describe('ChatsResource.mute', () => {+ // muteUntil must survive as the exact epoch-millisecond number given. A client that divided by+ // 1000, or stringified it, would still get a 200 back — the wrong unit is only visible here.+ it('sends muteUntil as epoch milliseconds, unchanged', async () => {+ const t = new MockTransport().on('POST', /\/chats\/mute$/, { body: { success: true } });+ await client(t).chats.mute('s', { chatId: '[email protected]', muteUntil: 1893456000000 });+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s/chats/mute');+ expect(t.lastCall!.body).toEqual({ chatId: '[email protected]', muteUntil: 1893456000000 });+ });++ // null is the unmute signal and is NOT the same as omitting the field, which the route rejects.+ it('sends an explicit null to unmute rather than dropping the key', async () => {+ const t = new MockTransport().on('POST', /\/chats\/mute$/, { body: { success: true } });+ await client(t).chats.mute('s', { chatId: '[email protected]', muteUntil: null });+ expect(t.lastCall!.body).toEqual({ chatId: '[email protected]', muteUntil: null });+ expect(Object.keys(t.lastCall!.body as object)).toContain('muteUntil');+ });+});+describe('HealthResource + auth — exact paths', () => {it('health/live/ready and auth validate', async () => {const t = new MockTransport()diff --git a/sdk/php/src/Resources/ChatsResource.php b/sdk/php/src/Resources/ChatsResource.phpindex 08d70c48c..7a9b247f0 100644--- a/sdk/php/src/Resources/ChatsResource.php+++ b/sdk/php/src/Resources/ChatsResource.php@@ -92,6 +92,35 @@ class ChatsResourcereturn $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/chats/archive", [], $body) ?? [];}+ /**+ * Pin a chat to the top of the list, or unpin it.+ *+ * `success: false` means WhatsApp declined — an account may pin only three chats at a time.+ *+ * @param array<string,mixed> $body chatId and pin (bool).+ * @return array<string,mixed>+ */+ public function pin(string $sessionId, array $body): array+ {+ return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/chats/pin", [], $body) ?? [];+ }++ /**+ * Mute a chat until an absolute timestamp, or unmute it with `muteUntil: null`.+ *+ * `muteUntil` is epoch MILLISECONDS. Passing seconds points at an instant in 1970, so the mute+ * expires the moment it is set while the call still succeeds — nothing in the response+ * distinguishes that from a mute that took effect. It is required, not optional: the two+ * readings of an omitted value, unmute now and mute indefinitely, are opposites.+ *+ * @param array<string,mixed> $body chatId and muteUntil (int epoch ms, or null to unmute).+ * @return array<string,mixed>+ */+ public function mute(string $sessionId, array $body): array+ {+ return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/chats/mute", [], $body) ?? [];+ }+/** @return array<string,mixed> */public function delete(string $sessionId, array $body): array{diff --git a/sdk/php/tests/ResourcesTest.php b/sdk/php/tests/ResourcesTest.phpindex 67e18b4bf..b61cd3deb 100644--- a/sdk/php/tests/ResourcesTest.php+++ b/sdk/php/tests/ResourcesTest.php@@ -311,6 +311,48 @@ class ResourcesTest extends TestCase$this->assertSame('POST', $backend->lastCall()['method']);}+ public function testChatsPinPostsTheFlag(): void+ {+ $backend = new MockBackend();+ $backend->on(200, ['success' => true]);+ $client = $backend->makeClient();+ $client->chats->pin('s', ['chatId' => '[email protected]', 'pin' => true]);+ $this->assertSame('/api/sessions/s/chats/pin', $backend->lastCall()['path']);+ $this->assertSame('POST', $backend->lastCall()['method']);+ $this->assertSame(['chatId' => '[email protected]', 'pin' => true], $backend->lastCall()['body']);+ }++ public function testChatsPinReportsRefusalRatherThanThrowing(): void+ {+ $backend = new MockBackend();+ $backend->on(200, ['success' => false]);+ $client = $backend->makeClient();+ $this->assertSame(['success' => false], $client->chats->pin('s', ['chatId' => '[email protected]', 'pin' => true]));+ }++ public function testChatsMuteSendsEpochMillisecondsUnchanged(): void+ {+ // The value must arrive as the exact millisecond number given. A client that divided by 1000+ // would still get a 200 back; the wrong unit is only visible on the wire.+ $backend = new MockBackend();+ $backend->on(200, ['success' => true]);+ $client = $backend->makeClient();+ $client->chats->mute('s', ['chatId' => '[email protected]', 'muteUntil' => 1893456000000]);+ $this->assertSame('/api/sessions/s/chats/mute', $backend->lastCall()['path']);+ $this->assertSame(['chatId' => '[email protected]', 'muteUntil' => 1893456000000], $backend->lastCall()['body']);+ }++ public function testChatsMuteSendsExplicitNullToUnmute(): void+ {+ // null is the unmute signal and is NOT the same as omitting the key, which the route rejects.+ $backend = new MockBackend();+ $backend->on(200, ['success' => true]);+ $client = $backend->makeClient();+ $client->chats->mute('s', ['chatId' => '[email protected]', 'muteUntil' => null]);+ $this->assertArrayHasKey('muteUntil', $backend->lastCall()['body']);+ $this->assertNull($backend->lastCall()['body']['muteUntil']);+ }+// ── Status (Stories) ──────────────────────────────────────────────public function testStatusSendForwardsRequiredRecipientsAndNestedMedia(): voiddiff --git a/sdk/python/openwa/resources/chats.py b/sdk/python/openwa/resources/chats.pyindex 7fcc05b28..3ec599ccc 100644--- a/sdk/python/openwa/resources/chats.py+++ b/sdk/python/openwa/resources/chats.py@@ -12,6 +12,8 @@ from .._http import quote_segmentfrom ..types import (ChatPresence,ArchiveChatRequest,+ PinChatRequest,+ MuteChatRequest,ChatSummary,DeleteChatRequest,MarkChatRequest,@@ -67,6 +69,22 @@ class ChatsResource:"""Archive or unarchive a chat. success=False means the engine declined."""return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/chats/archive", body=body)+ def pin(self, session_id: str, body: PinChatRequest) -> SuccessResult:+ """Pin a chat to the top of the list, or unpin it.++ success=False means WhatsApp declined — an account may pin only three chats at a time.+ """+ return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/chats/pin", body=body)++ def mute(self, session_id: str, body: MuteChatRequest) -> SuccessResult:+ """Mute a chat until an absolute timestamp, or unmute it with ``muteUntil=None``.++ ``muteUntil`` is epoch **milliseconds**. Passing seconds points at an instant in 1970, so the+ mute expires the moment it is set while the call still succeeds — nothing in the response+ distinguishes that from a mute that took effect.+ """+ return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/chats/mute", body=body)+def clear_messages(self, session_id: str, chat_id: str) -> SuccessResult:"""Delete every message in a chat, keeping the chat. success=False means the engine declined."""return self._http.request(diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.pyindex d635dc600..922b1dab5 100644--- a/sdk/python/openwa/types.py+++ b/sdk/python/openwa/types.py@@ -843,6 +843,26 @@ class ArchiveChatRequest(TypedDict):archive: bool+class PinChatRequest(TypedDict):+ """Pin a chat to the top of the list, or unpin it."""++ chatId: str+ pin: bool+++class MuteChatRequest(TypedDict):+ """Mute a chat until an absolute timestamp, or unmute it.++ ``muteUntil`` is epoch **milliseconds**, or ``None`` to unmute now. Milliseconds, not seconds:+ a seconds-scale value is an instant in 1970, so the mute expires immediately while the request+ still answers 200. Required rather than optional because the two readings of an omitted value,+ unmute now and mute indefinitely, are opposites.+ """++ chatId: str+ muteUntil: Optional[int]++class VotePollRequest(TypedDict):"""Vote on a poll. options are option TEXTS (no ids); [] clears the vote."""diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.pyindex 532da405f..f2b02c251 100644--- a/sdk/python/tests/test_sdk.py+++ b/sdk/python/tests/test_sdk.py@@ -661,6 +661,31 @@ class TestChatsAndHealth:assert backend.last_call.url == "http://localhost:2785/api/sessions/s/chats/archive"assert backend.last_call.body == {"chatId": "[email protected]", "archive": True}+ def test_chats_pin(self):+ backend = MockBackend().on("POST", "/chats/pin", body={"success": True})+ make_client(backend).chats.pin("s", {"chatId": "[email protected]", "pin": True})+ assert backend.last_call.url == "http://localhost:2785/api/sessions/s/chats/pin"+ assert backend.last_call.body == {"chatId": "[email protected]", "pin": True}++ def test_chats_pin_reports_refusal(self):+ backend = MockBackend().on("POST", "/chats/pin", body={"success": False})+ assert make_client(backend).chats.pin("s", {"chatId": "[email protected]", "pin": True}) == {"success": False}++ def test_chats_mute_sends_epoch_milliseconds_unchanged(self):+ # The value must arrive as the exact millisecond number given. A client that divided by 1000+ # would still get a 200 back; the wrong unit is only visible on the wire.+ backend = MockBackend().on("POST", "/chats/mute", body={"success": True})+ make_client(backend).chats.mute("s", {"chatId": "[email protected]", "muteUntil": 1893456000000})+ assert backend.last_call.url == "http://localhost:2785/api/sessions/s/chats/mute"+ assert backend.last_call.body == {"chatId": "[email protected]", "muteUntil": 1893456000000}++ def test_chats_mute_sends_explicit_null_to_unmute(self):+ # None is the unmute signal and is NOT the same as omitting the key, which the route rejects.+ backend = MockBackend().on("POST", "/chats/mute", body={"success": True})+ make_client(backend).chats.mute("s", {"chatId": "[email protected]", "muteUntil": None})+ assert backend.last_call.body == {"chatId": "[email protected]", "muteUntil": None}+ assert "muteUntil" in backend.last_call.body+def test_health_and_auth(self):backend = MockBackend()backend.on("GET", "/api/health", body={"status": "ok", "version": "0.7.2"})