Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(sdk): expose the channel administration routes in all five clients
Yudhi Armyndharis94847fd0c795
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a0efc5fa2..8ee5adaf1 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- The JavaScript, Python, PHP, Go and Java SDKs expose the three group membership-request routes — list, approve and reject; omitting the participant list acts on every pending request, and a partial refusal still answers `200` with each outcome in `results`.- The JavaScript, Python, PHP, Go and Java SDKs expose `GET /sessions/:sessionId/contacts/blocked` as `listBlocked` (`list_blocked` in Python), reading back what `block` and `unblock` have done. It needs only a read-level key.- The JavaScript, Python, PHP, Go and Java SDKs expose `POST /sessions/:sessionId/calls/link`, which creates a shareable WhatsApp call link. `startTime` is absolute epoch milliseconds and is required, so a link for right now carries the current timestamp rather than an omitted field.+- The JavaScript, Python, PHP, Go and Java SDKs expose the two channel administration routes — demote an admin back to a subscriber, and transfer ownership. Both need an `OPERATOR` key, the transfer is irreversible, and the whatsapp-web.js engine answers `501` for either.### Fixeddiff --git a/docs/18-sdk-design.md b/docs/18-sdk-design.mdindex 024e5be47..0d5f2e5ec 100644--- a/docs/18-sdk-design.md+++ b/docs/18-sdk-design.md@@ -35,7 +35,7 @@ All five SDKs expose the same fluent surface:| `webhooks` | list, listAll, deliveryFailures, get, create, update, delete, test || `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)_ |+| `channels` | list, get, messages, create, delete, mute, subscribe, unsubscribe, demoteAdmin, transferOwnership _(Newsletters)_ || `catalog` | info, products, product, sendProduct, sendCatalog _(WhatsApp Business)_ || `status` | list, fromContact, media, sendText, sendImage, sendVideo, sendVoice, delete _(Stories)_ || `search` | search |@@ -261,16 +261,18 @@ Media bodies share the `SendMediaRequest` shape: `{ chatId, url? | base64?, mime#### `channels` _(Newsletters)_-| Method | Signature | Description |-| ------------- | ---------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |-| `list` | `list(sessionId)` | List all channels/newsletters the session is subscribed to. |-| `get` | `get(sessionId, channelId)` | Get a single channel by id. |-| `messages` | `messages(sessionId, channelId, query?)` | Get recent messages from a channel. |-| `create` | `create(sessionId, body)` | Create a channel this account owns. **OPERATOR** |-| `delete` | `delete(sessionId, channelId)` | Delete a channel this account owns. Irreversible, and every subscriber loses it — distinct from `unsubscribe`. **OPERATOR** |-| `mute` | `mute(sessionId, channelId, body)` | Mute or unmute a channel's notifications. **OPERATOR** |-| `subscribe` | `subscribe(sessionId, body)` | Subscribe to a channel using its invite code. **OPERATOR** |-| `unsubscribe` | `unsubscribe(sessionId, channelId)` | Unsubscribe from a channel. **OPERATOR** |+| Method | Signature | Description |+| ------------------- | ----------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |+| `list` | `list(sessionId)` | List all channels/newsletters the session is subscribed to. |+| `get` | `get(sessionId, channelId)` | Get a single channel by id. |+| `messages` | `messages(sessionId, channelId, query?)` | Get recent messages from a channel. |+| `create` | `create(sessionId, body)` | Create a channel this account owns. **OPERATOR** |+| `delete` | `delete(sessionId, channelId)` | Delete a channel this account owns. Irreversible, and every subscriber loses it — distinct from `unsubscribe`. **OPERATOR** |+| `mute` | `mute(sessionId, channelId, body)` | Mute or unmute a channel's notifications. **OPERATOR** |+| `subscribe` | `subscribe(sessionId, body)` | Subscribe to a channel using its invite code. **OPERATOR** |+| `unsubscribe` | `unsubscribe(sessionId, channelId)` | Unsubscribe from a channel. **OPERATOR** |+| `demoteAdmin` | `demoteAdmin(sessionId, channelId, body)` | Demote a channel admin back to a subscriber; no promote counterpart exists. **OPERATOR** |+| `transferOwnership` | `transferOwnership(sessionId, channelId, body)` | Hand a channel to a new owner. Irreversible. **OPERATOR** |#### `catalog` _(WhatsApp Business)_@@ -628,16 +630,18 @@ Resources are accessed as properties on the client (e.g. `client.messages`). All#### `client.channels` _(Newsletters)_-| Method | Signature | Description |-| ------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |-| `list` | `list(session_id) -> list[ChannelRecord]` | List subscribed channels. |-| `get` | `get(session_id, channel_id) -> ChannelRecord` | Get one channel. |-| `messages` | `messages(session_id, channel_id, query=None) -> list[ChannelMessageRecord]` | List channel messages. |-| `create` | `create(session_id, body) -> ChannelRecord` | Create a channel this account owns. **OPERATOR** |-| `delete` | `delete(session_id, channel_id) -> SuccessResult` | Delete a channel this account owns. Irreversible, and every subscriber loses it — distinct from `unsubscribe`. **OPERATOR** |-| `mute` | `mute(session_id, channel_id, body) -> SuccessResult` | Mute or unmute a channel's notifications. **OPERATOR** |-| `subscribe` | `subscribe(session_id, body) -> ChannelRecord` | Subscribe via invite code. **OPERATOR** |-| `unsubscribe` | `unsubscribe(session_id, channel_id) -> SuccessResult` | Unsubscribe from a channel. **OPERATOR** |+| Method | Signature | Description |+| -------------------- | ---------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |+| `list` | `list(session_id) -> list[ChannelRecord]` | List subscribed channels. |+| `get` | `get(session_id, channel_id) -> ChannelRecord` | Get one channel. |+| `messages` | `messages(session_id, channel_id, query=None) -> list[ChannelMessageRecord]` | List channel messages. |+| `create` | `create(session_id, body) -> ChannelRecord` | Create a channel this account owns. **OPERATOR** |+| `delete` | `delete(session_id, channel_id) -> SuccessResult` | Delete a channel this account owns. Irreversible, and every subscriber loses it — distinct from `unsubscribe`. **OPERATOR** |+| `mute` | `mute(session_id, channel_id, body) -> SuccessResult` | Mute or unmute a channel's notifications. **OPERATOR** |+| `subscribe` | `subscribe(session_id, body) -> ChannelRecord` | Subscribe via invite code. **OPERATOR** |+| `unsubscribe` | `unsubscribe(session_id, channel_id) -> SuccessResult` | Unsubscribe from a channel. **OPERATOR** |+| `demote_admin` | `demote_admin(session_id, channel_id, body) -> SuccessResult` | Demote a channel admin back to a subscriber; no promote counterpart exists. **OPERATOR** |+| `transfer_ownership` | `transfer_ownership(session_id, channel_id, body) -> SuccessResult` | Hand a channel to a new owner. Irreversible. **OPERATOR** |#### `client.catalog` _(WhatsApp Business)_@@ -968,16 +972,18 @@ All payloads are associative arrays; all listed methods are synchronous and retu#### `channels` _(Newsletters)_-| Method | Signature | Description |-| ------------- | -------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |-| `list` | `list(string $sessionId): array` | List channels. |-| `get` | `get(string $sessionId, string $channelId): array` | Get one channel. |-| `messages` | `messages(string $sessionId, string $channelId, array $query = []): array` | Recent channel messages. |-| `create` | `create(string $sessionId, array $body): array` | Create a channel this account owns. **OPERATOR** |-| `delete` | `delete(string $sessionId, string $channelId): array` | Delete a channel this account owns. Irreversible, and every subscriber loses it — distinct from `unsubscribe`. **OPERATOR** |-| `mute` | `mute(string $sessionId, string $channelId, array $body): array` | Mute or unmute a channel's notifications. **OPERATOR** |-| `subscribe` | `subscribe(string $sessionId, array $body): array` | Subscribe via invite code (`$body` needs `inviteCode`). **OPERATOR** |-| `unsubscribe` | `unsubscribe(string $sessionId, string $channelId): array` | Unsubscribe from a channel. **OPERATOR** |+| Method | Signature | Description |+| ------------------- | ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |+| `list` | `list(string $sessionId): array` | List channels. |+| `get` | `get(string $sessionId, string $channelId): array` | Get one channel. |+| `messages` | `messages(string $sessionId, string $channelId, array $query = []): array` | Recent channel messages. |+| `create` | `create(string $sessionId, array $body): array` | Create a channel this account owns. **OPERATOR** |+| `delete` | `delete(string $sessionId, string $channelId): array` | Delete a channel this account owns. Irreversible, and every subscriber loses it — distinct from `unsubscribe`. **OPERATOR** |+| `mute` | `mute(string $sessionId, string $channelId, array $body): array` | Mute or unmute a channel's notifications. **OPERATOR** |+| `subscribe` | `subscribe(string $sessionId, array $body): array` | Subscribe via invite code (`$body` needs `inviteCode`). **OPERATOR** |+| `unsubscribe` | `unsubscribe(string $sessionId, string $channelId): array` | Unsubscribe from a channel. **OPERATOR** |+| `demoteAdmin` | `demoteAdmin(string $sessionId, string $channelId, array $body): array` | Demote a channel admin back to a subscriber; no promote counterpart exists. **OPERATOR** |+| `transferOwnership` | `transferOwnership(string $sessionId, string $channelId, array $body): array` | Hand a channel to a new owner. Irreversible. **OPERATOR** |#### `catalog` _(WhatsApp Business)_diff --git a/sdk/README.md b/sdk/README.mdindex 545fa6d9f..e6e979787 100644--- a/sdk/README.md+++ b/sdk/README.md@@ -31,7 +31,7 @@ All five SDKs expose the same fluent resource surface:| `webhooks` | list, listAll, deliveryFailures, get, create, update, delete, test || `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)_ |+| `channels` | list, get, messages, create, delete, mute, subscribe, unsubscribe, demoteAdmin, transferOwnership _(Newsletters)_ || `catalog` | info, products, product, sendProduct, sendCatalog _(WhatsApp Business)_ || `status` | list, fromContact, media, sendText, sendImage, sendVideo, sendVoice, delete _(Stories)_ || `search` | search _(Operator)_ |diff --git a/sdk/go/channels.go b/sdk/go/channels.goindex 120bb9ca7..86713ea42 100644--- a/sdk/go/channels.go+++ b/sdk/go/channels.go@@ -77,3 +77,33 @@ func (s *ChannelsService) Unsubscribe(ctx context.Context, sessionID, channelID}return &out, nil}++// DemoteAdmin demotes a channel admin back to a subscriber. Requires an OPERATOR-level key.+//+// There is no promote counterpart: neither engine library has one, so an admin is promoted from the+// WhatsApp app and demoted here. The whatsapp-web.js engine answers 501.+func (s *ChannelsService) DemoteAdmin(+ ctx context.Context, sessionID, channelID string, body DemoteChannelAdminRequest,+) (*SuccessResult, error) {+ var out SuccessResult+ err := s.client.do(ctx, "POST", s.base(sessionID)+"/"+pathEscape(channelID)+"/admins/demote", nil, body, &out)+ if err != nil {+ return nil, err+ }+ return &out, nil+}++// TransferOwnership hands a channel to a new owner. Requires an OPERATOR-level key.+//+// Irreversible: once the transfer lands this account stops being the owner and cannot take the+// channel back. The whatsapp-web.js engine answers 501.+func (s *ChannelsService) TransferOwnership(+ ctx context.Context, sessionID, channelID string, body TransferChannelOwnershipRequest,+) (*SuccessResult, error) {+ var out SuccessResult+ err := s.client.do(ctx, "POST", s.base(sessionID)+"/"+pathEscape(channelID)+"/owner/transfer", nil, body, &out)+ if err != nil {+ return nil, err+ }+ return &out, nil+}diff --git a/sdk/go/routing_test.go b/sdk/go/routing_test.goindex 191a2bafd..8965938b3 100644--- a/sdk/go/routing_test.go+++ b/sdk/go/routing_test.go@@ -136,6 +136,8 @@ func TestRouting(t *testing.T) {{"Channels.Messages", func(c *Client) { c.Channels.Messages(ctx, "s1", "ch1", nil) }, "GET", "/api/sessions/s1/channels/ch1/messages"},{"Channels.Subscribe", func(c *Client) { c.Channels.Subscribe(ctx, "s1", SubscribeChannelRequest{}) }, "POST", "/api/sessions/s1/channels/subscribe"},{"Channels.Unsubscribe", func(c *Client) { c.Channels.Unsubscribe(ctx, "s1", "ch1") }, "DELETE", "/api/sessions/s1/channels/ch1"},+ {"Channels.DemoteAdmin", func(c *Client) { c.Channels.DemoteAdmin(ctx, "s1", "c1", DemoteChannelAdminRequest{}) }, "POST", "/api/sessions/s1/channels/c1/admins/demote"},+ {"Channels.TransferOwnership", func(c *Client) { c.Channels.TransferOwnership(ctx, "s1", "c1", TransferChannelOwnershipRequest{}) }, "POST", "/api/sessions/s1/channels/c1/owner/transfer"},{"Catalog.Info", func(c *Client) { c.Catalog.Info(ctx, "s1") }, "GET", "/api/sessions/s1/catalog"},{"Catalog.Products", func(c *Client) { c.Catalog.Products(ctx, "s1", nil) }, "GET", "/api/sessions/s1/catalog/products"},diff --git a/sdk/go/types_session.go b/sdk/go/types_session.goindex 793f1f38f..780d12049 100644--- a/sdk/go/types_session.go+++ b/sdk/go/types_session.go@@ -36,6 +36,17 @@ type CreateChannelRequest struct {Description string `json:"description,omitempty"`}+// DemoteChannelAdminRequest is the body for ChannelsService.DemoteAdmin.+type DemoteChannelAdminRequest struct {+ UserID string `json:"userId"`+}++// TransferChannelOwnershipRequest is the body for ChannelsService.TransferOwnership. The transfer+// is irreversible.+type TransferChannelOwnershipRequest struct {+ NewOwnerID string `json:"newOwnerId"`+}+// MuteChannelRequest is the body for muting or unmuting a channel. The subscription is unaffected// either way.type MuteChannelRequest struct {diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/DemoteChannelAdminRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/DemoteChannelAdminRequest.javanew file mode 100644index 000000000..cbdddddc0--- /dev/null+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/DemoteChannelAdminRequest.java@@ -0,0 +1,26 @@+package com.rmyndharis.openwa.model;++/**+ * Request body for demoting a channel admin back to a subscriber.+ *+ * @param userId WhatsApp ID of the admin to demote+ */+public record DemoteChannelAdminRequest(String userId) {+ public static Builder builder() {+ return new Builder();+ }++ public static final class Builder {+ private String userId;++ /** WhatsApp ID of the admin to demote back to a subscriber. */+ public Builder userId(String v) {+ this.userId = v;+ return this;+ }++ public DemoteChannelAdminRequest build() {+ return new DemoteChannelAdminRequest(userId);+ }+ }+}diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/TransferChannelOwnershipRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/TransferChannelOwnershipRequest.javanew file mode 100644index 000000000..b2fe36f25--- /dev/null+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/TransferChannelOwnershipRequest.java@@ -0,0 +1,28 @@+package com.rmyndharis.openwa.model;++/**+ * Request body for handing a channel to a new owner.+ *+ * <p>The transfer is irreversible: once it lands, this session can no longer take the channel back.+ *+ * @param newOwnerId WhatsApp ID of the account that becomes the new owner+ */+public record TransferChannelOwnershipRequest(String newOwnerId) {+ public static Builder builder() {+ return new Builder();+ }++ public static final class Builder {+ private String newOwnerId;++ /** WhatsApp ID of the account that becomes the new owner. */+ public Builder newOwnerId(String v) {+ this.newOwnerId = v;+ return this;+ }++ public TransferChannelOwnershipRequest build() {+ return new TransferChannelOwnershipRequest(newOwnerId);+ }+ }+}diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ChannelsResource.java b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ChannelsResource.javaindex fd6d45a26..3a9a10343 100644--- a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ChannelsResource.java+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ChannelsResource.java@@ -8,7 +8,9 @@ import com.rmyndharis.openwa.model.ChannelMessageQuery;import com.rmyndharis.openwa.model.ChannelMessageRecord;import com.rmyndharis.openwa.model.ChannelRecord;import com.rmyndharis.openwa.model.CreateChannelRequest;+import com.rmyndharis.openwa.model.DemoteChannelAdminRequest;import com.rmyndharis.openwa.model.MuteChannelRequest;+import com.rmyndharis.openwa.model.TransferChannelOwnershipRequest;import com.rmyndharis.openwa.model.SubscribeChannelRequest;import com.rmyndharis.openwa.model.SuccessResult;import java.util.List;@@ -101,4 +103,34 @@ public final class ChannelsResource {null,SuccessResult.class);}+ /**+ * Demote a channel admin back to a subscriber. Requires an OPERATOR-level key.+ *+ * <p>There is no promote counterpart: neither engine library has one, so an admin is promoted+ * from the WhatsApp app and demoted here. The whatsapp-web.js engine answers {@code 501}.+ */+ public SuccessResult demoteAdmin(String sessionId, String channelId, DemoteChannelAdminRequest body) {+ return client.request(+ HttpMethod.POST,+ "/api/sessions/" + encodeSegment(sessionId) + "/channels/" + encodeSegment(channelId) + "/admins/demote",+ null,+ body,+ SuccessResult.class);+ }++ /**+ * Hand a channel to a new owner. Requires an OPERATOR-level key.+ *+ * <p><b>Irreversible</b>: once the transfer lands this account stops being the owner and cannot+ * take the channel back. The whatsapp-web.js engine answers {@code 501}.+ */+ public SuccessResult transferOwnership(String sessionId, String channelId, TransferChannelOwnershipRequest body) {+ return client.request(+ HttpMethod.POST,+ "/api/sessions/" + encodeSegment(sessionId) + "/channels/" + encodeSegment(channelId) + "/owner/transfer",+ null,+ body,+ SuccessResult.class);+ }+}diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ChannelsResourceTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ChannelsResourceTest.javaindex a84c6f69d..522b7fc06 100644--- a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ChannelsResourceTest.java+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ChannelsResourceTest.java@@ -11,6 +11,8 @@ import com.rmyndharis.openwa.model.ChannelMessageRecord;import com.rmyndharis.openwa.model.ChannelRecord;import com.rmyndharis.openwa.model.SubscribeChannelRequest;import com.rmyndharis.openwa.support.MockTransport;+import com.rmyndharis.openwa.model.DemoteChannelAdminRequest;+import com.rmyndharis.openwa.model.TransferChannelOwnershipRequest;import org.junit.jupiter.api.Test;class ChannelsResourceTest {@@ -99,4 +101,18 @@ class ChannelsResourceTest {assertEquals("http://h/api/sessions/s/channels/123@newsletter", tx.lastRequest().url());assertEquals(HttpMethod.DELETE, tx.lastRequest().method());}+ @Test+ void demoteAdminAndTransferOwnershipHitTheirOwnPaths() {+ tx.respond(200, "{\"success\":true}");+ client.channels.demoteAdmin("s", "c", DemoteChannelAdminRequest.builder().userId("[email protected]").build());+ assertEquals("http://h/api/sessions/s/channels/c/admins/demote", tx.lastRequest().url());+ assertTrue(tx.lastRequest().body().contains("[email protected]"));++ tx.respond(200, "{\"success\":true}");+ client.channels.transferOwnership(+ "s", "c", TransferChannelOwnershipRequest.builder().newOwnerId("[email protected]").build());+ assertEquals("http://h/api/sessions/s/channels/c/owner/transfer", tx.lastRequest().url());+ assertTrue(tx.lastRequest().body().contains("[email protected]"));+ }+}diff --git a/sdk/javascript/src/resources/channels.ts b/sdk/javascript/src/resources/channels.tsindex 8e6a993e9..4747aaeb2 100644--- a/sdk/javascript/src/resources/channels.ts+++ b/sdk/javascript/src/resources/channels.ts@@ -9,7 +9,9 @@ import { encodeSegment } from '../http.js';import type { OpenWAClient } from '../client.js';import type {CreateChannelRequest,+ DemoteChannelAdminRequest,MuteChannelRequest,+ TransferChannelOwnershipRequest,ChannelMessageQuery,ChannelMessageRecord,ChannelRecord,@@ -92,4 +94,35 @@ export class ChannelsResource {path: `/api/sessions/${encodeSegment(sessionId)}/channels/${encodeSegment(channelId)}`,});}+ /**+ * Demote a channel admin back to a subscriber. Requires an OPERATOR-level key.+ *+ * There is no promote counterpart: neither engine library has one, so an admin is promoted from+ * the WhatsApp app and demoted here. The whatsapp-web.js engine answers `501`.+ */+ demoteAdmin(sessionId: string, channelId: string, body: DemoteChannelAdminRequest): Promise<SuccessResult> {+ return this.client.request<SuccessResult>({+ method: 'POST',+ path: `/api/sessions/${encodeSegment(sessionId)}/channels/${encodeSegment(channelId)}/admins/demote`,+ body,+ });+ }++ /**+ * Hand a channel to a new owner. Requires an OPERATOR-level key.+ *+ * **Irreversible**: once the transfer lands this account stops being the owner and cannot take the+ * channel back. The whatsapp-web.js engine answers `501`.+ */+ transferOwnership(+ sessionId: string,+ channelId: string,+ body: TransferChannelOwnershipRequest,+ ): Promise<SuccessResult> {+ return this.client.request<SuccessResult>({+ method: 'POST',+ path: `/api/sessions/${encodeSegment(sessionId)}/channels/${encodeSegment(channelId)}/owner/transfer`,+ body,+ });+ }}diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.tsindex 83e2fdfb2..254318c90 100644--- a/sdk/javascript/src/types.ts+++ b/sdk/javascript/src/types.ts@@ -851,6 +851,18 @@ export interface CallLinkResponse {link: string;}+/** Body for {@link ChannelsResource.demoteAdmin}. */+export interface DemoteChannelAdminRequest {+ /** WhatsApp ID of the admin to demote back to a subscriber. */+ userId: Jid;+}++/** Body for {@link ChannelsResource.transferOwnership}. */+export interface TransferChannelOwnershipRequest {+ /** WhatsApp ID of the account that becomes the new owner. */+ newOwnerId: Jid;+}+export interface MarkChatRequest {chatId: Jid;}diff --git a/sdk/javascript/test/labels-channels-catalog.test.ts b/sdk/javascript/test/labels-channels-catalog.test.tsindex 226249ac7..f2f78d96a 100644--- a/sdk/javascript/test/labels-channels-catalog.test.ts+++ b/sdk/javascript/test/labels-channels-catalog.test.ts@@ -136,3 +136,20 @@ describe('Client exposes all resources', () => {}});});++describe('ChannelsResource — admin and ownership', () => {+ it('demoteAdmin and transferOwnership post to their own paths', async () => {+ const t = new MockTransport()+ .on('POST', /\/admins\/demote$/, { body: { success: true } })+ .on('POST', /\/owner\/transfer$/, { body: { success: true } });+ const c = client(t);++ await c.channels.demoteAdmin('s', 'c@newsletter', { userId: '[email protected]' });+ expect(t.lastCall!.url).toContain('/api/sessions/s/channels/c@newsletter/admins/demote');+ expect(t.lastCall!.body).toEqual({ userId: '[email protected]' });++ await c.channels.transferOwnership('s', 'c@newsletter', { newOwnerId: '[email protected]' });+ expect(t.lastCall!.url).toContain('/api/sessions/s/channels/c@newsletter/owner/transfer');+ expect(t.lastCall!.body).toEqual({ newOwnerId: '[email protected]' });+ });+});diff --git a/sdk/php/src/Resources/ChannelsResource.php b/sdk/php/src/Resources/ChannelsResource.phpindex 5af671024..ef9f85d4e 100644--- a/sdk/php/src/Resources/ChannelsResource.php+++ b/sdk/php/src/Resources/ChannelsResource.php@@ -93,4 +93,32 @@ class ChannelsResource{return $this->http->request('DELETE', "/api/sessions/{$this->http->encodeSegment($sessionId)}/channels/{$this->http->encodeSegment($channelId)}");}+ /**+ * Demote a channel admin back to a subscriber. Requires an OPERATOR-level key.+ *+ * There is no promote counterpart: neither engine library has one, so an admin is promoted from+ * the WhatsApp app and demoted here. The whatsapp-web.js engine answers `501`.+ *+ * @param array{userId:string} $body+ * @return array<string,mixed>+ */+ public function demoteAdmin(string $sessionId, string $channelId, array $body): array+ {+ return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/channels/{$this->http->encodeSegment($channelId)}/admins/demote", [], $body);+ }++ /**+ * Hand a channel to a new owner. Requires an OPERATOR-level key.+ *+ * Irreversible: once the transfer lands this account stops being the owner and cannot take the+ * channel back. The whatsapp-web.js engine answers `501`.+ *+ * @param array{newOwnerId:string} $body+ * @return array<string,mixed>+ */+ public function transferOwnership(string $sessionId, string $channelId, array $body): array+ {+ return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/channels/{$this->http->encodeSegment($channelId)}/owner/transfer", [], $body);+ }+}diff --git a/sdk/php/tests/LabelsChannelsCatalogTest.php b/sdk/php/tests/LabelsChannelsCatalogTest.phpindex 68f157075..59e3e7228 100644--- a/sdk/php/tests/LabelsChannelsCatalogTest.php+++ b/sdk/php/tests/LabelsChannelsCatalogTest.php@@ -78,4 +78,20 @@ class LabelsChannelsCatalogTest extends TestCase$this->assertTrue(property_exists($client, $r), "Client should expose resource: {$r}");}}+ public function testChannelAdminAndOwnership(): void+ {+ $backend = new MockBackend();+ $backend->on(200, ['success' => true]);+ $backend->on(200, ['success' => true]);+ $client = $backend->makeClient();++ $client->channels->demoteAdmin('s', 'c@newsletter', ['userId' => '[email protected]']);+ $this->assertStringEndsWith('/channels/c@newsletter/admins/demote', $backend->lastCall()['url']);+ $this->assertSame(['userId' => '[email protected]'], $backend->lastCall()['body']);++ $client->channels->transferOwnership('s', 'c@newsletter', ['newOwnerId' => '[email protected]']);+ $this->assertStringEndsWith('/channels/c@newsletter/owner/transfer', $backend->lastCall()['url']);+ $this->assertSame(['newOwnerId' => '[email protected]'], $backend->lastCall()['body']);+ }+}diff --git a/sdk/python/openwa/resources/channels.py b/sdk/python/openwa/resources/channels.pyindex cda4d57f6..0d763efd2 100644--- a/sdk/python/openwa/resources/channels.py+++ b/sdk/python/openwa/resources/channels.py@@ -17,6 +17,8 @@ from ..types import (ChannelRecord,SubscribeChannelRequest,SuccessResult,+ DemoteChannelAdminRequest,+ TransferChannelOwnershipRequest,)if TYPE_CHECKING:@@ -67,3 +69,29 @@ class ChannelsResource:def unsubscribe(self, session_id: str, channel_id: str) -> SuccessResult:"""Unsubscribe from a channel. Requires an OPERATOR-level key."""return self._http.request("DELETE", f"/api/sessions/{quote_segment(session_id)}/channels/{quote_segment(channel_id)}")++ def demote_admin(self, session_id: str, channel_id: str, body: DemoteChannelAdminRequest) -> SuccessResult:+ """Demote a channel admin back to a subscriber. Requires an OPERATOR-level key.++ There is no promote counterpart: neither engine library has one, so an admin is promoted+ from the WhatsApp app and demoted here. The whatsapp-web.js engine answers 501.+ """+ return self._http.request(+ "POST",+ f"/api/sessions/{quote_segment(session_id)}/channels/{quote_segment(channel_id)}/admins/demote",+ body=body,+ )++ def transfer_ownership(+ self, session_id: str, channel_id: str, body: TransferChannelOwnershipRequest+ ) -> SuccessResult:+ """Hand a channel to a new owner. Requires an OPERATOR-level key.++ **Irreversible**: once the transfer lands this account stops being the owner and cannot take+ the channel back. The whatsapp-web.js engine answers 501.+ """+ return self._http.request(+ "POST",+ f"/api/sessions/{quote_segment(session_id)}/channels/{quote_segment(channel_id)}/owner/transfer",+ body=body,+ )diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.pyindex 7261ae74d..9b4023101 100644--- a/sdk/python/openwa/types.py+++ b/sdk/python/openwa/types.py@@ -66,6 +66,16 @@ class CallLinkResponse(TypedDict):"""The shareable WhatsApp call link."""link: str+class DemoteChannelAdminRequest(TypedDict):+ """Body for :meth:`ChannelsResource.demote_admin`."""++ userId: str+++class TransferChannelOwnershipRequest(TypedDict):+ """Body for :meth:`ChannelsResource.transfer_ownership`. The transfer is irreversible."""++ newOwnerId: strclass SuccessResult(TypedDict, total=False):diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.pyindex 9aa7f006e..71707dcb4 100644--- a/sdk/python/tests/test_sdk.py+++ b/sdk/python/tests/test_sdk.py@@ -896,3 +896,17 @@ class TestCallLink:assert backend.calls[-1].url.endswith("/sessions/s/calls/link")assert backend.calls[-1].body == {"type": "video", "startTime": 1800000000000}assert "call.whatsapp.com" in res["link"]+class TestChannelAdminOwnership:+ def test_demote_and_transfer(self):+ backend = MockBackend()+ backend.on("POST", "/admins/demote", body={"success": True})+ backend.on("POST", "/owner/transfer", body={"success": True})+ client = make_client(backend)++ client.channels.demote_admin("s", "c@newsletter", {"userId": "[email protected]"})+ assert backend.calls[-1].url.endswith("/channels/c@newsletter/admins/demote")+ assert backend.calls[-1].body == {"userId": "[email protected]"}++ client.channels.transfer_ownership("s", "c@newsletter", {"newOwnerId": "[email protected]"})+ assert backend.calls[-1].url.endswith("/channels/c@newsletter/owner/transfer")+ assert backend.calls[-1].body == {"newOwnerId": "[email protected]"}