Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(sdk): expose the blocked-contacts route in all five SDKs
Yudhi Armyndharisc92a97722fe2
diff --git a/docs/18-sdk-design.md b/docs/18-sdk-design.mdindex faedf77ad..100d30223 100644--- a/docs/18-sdk-design.md+++ b/docs/18-sdk-design.md@@ -30,7 +30,7 @@ All five SDKs expose the same fluent surface:| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- || `sessions` | list, get, getConfig, updateConfig, create, delete, start, stop, logout, forceKill, getQrCode, requestPairingCode, setOnlinePresence, stats || `messages` | list, sendText, sendImage/Video/Audio/Document/Sticker, sendLocation, sendContact, sendTemplate, sendPoll, reply, forward, react, delete, editMessage, history, reactions, media, pin, unpin, star, votePoll, sendBulk, batchStatus, cancelBatch |-| `contacts` | list, get, check, profilePicture, profilePictures, phone, upsert, delete, block, unblock |+| `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 |@@ -188,6 +188,7 @@ Media bodies share the `SendMediaRequest` shape: `{ chatId, url? | base64?, mime| `upsert` | `upsert(sessionId, contactId, body)` | Save a contact to the account's addressbook, or edit an existing entry. **OPERATOR** || `delete` | `delete(sessionId, contactId)` | Remove a contact from the account's addressbook. **OPERATOR** || `unblock` | `unblock(sessionId, contactId)` | Unblock a contact. **OPERATOR** |+| `listBlocked` | `listBlocked(sessionId)` | List the ids this account has blocked. Session-wide, so it takes no contact id. |#### `groups`@@ -551,6 +552,7 @@ Resources are accessed as properties on the client (e.g. `client.messages`). All| `upsert` | `upsert(session_id, contact_id, body) -> SuccessResult` | Save a contact to the account's addressbook, or edit an existing entry. **OPERATOR** || `delete` | `delete(session_id, contact_id) -> SuccessResult` | Remove a contact from the account's addressbook. **OPERATOR** || `unblock` | `unblock(session_id, contact_id) -> SuccessResult` | Unblock a contact. **OPERATOR** |+| `list_blocked` | `list_blocked(session_id) -> list[str]` | List the ids this account has blocked. Session-wide, so it takes no contact id. |#### `client.groups`@@ -887,6 +889,7 @@ All payloads are associative arrays; all listed methods are synchronous and retu| `upsert` | `upsert(string $sessionId, string $contactId, array $body): array` | Save a contact to the account's addressbook, or edit an existing entry. **OPERATOR** || `delete` | `delete(string $sessionId, string $contactId): array` | Remove a contact from the account's addressbook. **OPERATOR** || `unblock` | `unblock(string $sessionId, string $contactId): array` | Unblock a contact. **OPERATOR** |+| `listBlocked` | `listBlocked(string $sessionId): array` | List the ids this account has blocked. Session-wide, so it takes no contact id. |#### `groups`diff --git a/sdk/README.md b/sdk/README.mdindex 1e44807de..91b121cc8 100644--- a/sdk/README.md+++ b/sdk/README.md@@ -26,7 +26,7 @@ All five SDKs expose the same fluent resource surface:| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ || `sessions` | list, get, getConfig, updateConfig, create, delete, start, stop, logout, forceKill, getQrCode, requestPairingCode, setOnlinePresence, stats || `messages` | list, sendText, sendImage/Video/Audio/Document/Sticker, sendLocation, sendContact, sendTemplate, sendPoll, reply, forward, react, delete, editMessage, history, reactions, media, pin, unpin, star, votePoll, sendBulk, batchStatus, cancelBatch |-| `contacts` | list, get, check, profilePicture, profilePictures, phone, upsert, delete, block, unblock |+| `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 |diff --git a/sdk/go/contacts.go b/sdk/go/contacts.goindex 0cb75419f..320a66ba8 100644--- a/sdk/go/contacts.go+++ b/sdk/go/contacts.go@@ -111,3 +111,11 @@ func (s *ContactsService) Unblock(ctx context.Context, sessionID, contactID stri}return &out, nil}++// ListBlocked returns the JIDs this account has blocked. Session-wide, so it takes no contact ID —+// unlike Block and Unblock, which act on one contact — and it returns bare IDs, not contact records.+func (s *ContactsService) ListBlocked(ctx context.Context, sessionID string) ([]string, error) {+ var out []string+ err := s.client.do(ctx, "GET", s.base(sessionID)+"/blocked", nil, nil, &out)+ return out, err+}diff --git a/sdk/go/routing_test.go b/sdk/go/routing_test.goindex 203b36a11..473aceff0 100644--- a/sdk/go/routing_test.go+++ b/sdk/go/routing_test.go@@ -62,6 +62,7 @@ func TestRouting(t *testing.T) {{"Contacts.Delete", func(c *Client) { c.Contacts.Delete(ctx, "s1", "c1") }, "DELETE", "/api/sessions/s1/contacts/c1"},{"Contacts.Block", func(c *Client) { c.Contacts.Block(ctx, "s1", "u1") }, "POST", "/api/sessions/s1/contacts/u1/block"},{"Contacts.Unblock", func(c *Client) { c.Contacts.Unblock(ctx, "s1", "u1") }, "DELETE", "/api/sessions/s1/contacts/u1/block"},+ {"Contacts.ListBlocked", func(c *Client) { c.Contacts.ListBlocked(ctx, "s1") }, "GET", "/api/sessions/s1/contacts/blocked"},{"Groups.GetPicture", func(c *Client) { c.Groups.GetPicture(ctx, "s1", "g1") }, "GET", "/api/sessions/s1/groups/g1/picture"},{"Groups.SetPicture", func(c *Client) { c.Groups.SetPicture(ctx, "s1", "g1", SetGroupPictureRequest{}) }, "PUT", "/api/sessions/s1/groups/g1/picture"},diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ContactsResource.java b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ContactsResource.javaindex b7f988b02..82485ccaf 100644--- a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ContactsResource.java+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/ContactsResource.java@@ -125,4 +125,18 @@ public final class ContactsResource {null,SuccessResult.class);}++ /**+ * List the JIDs this account has blocked. Session-wide, so it takes no contact id — unlike+ * {@link #block} and {@link #unblock}, which act on one contact — and it returns bare ids+ * rather than contact records.+ */+ public List<String> listBlocked(String sessionId) {+ return client.requestList(+ HttpMethod.GET,+ "/api/sessions/" + encodeSegment(sessionId) + "/contacts/blocked",+ null,+ null,+ String.class);+ }}diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ContactsResourceTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ContactsResourceTest.javaindex a1e300abe..8fcd2b55a 100644--- a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ContactsResourceTest.java+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ContactsResourceTest.java@@ -96,6 +96,17 @@ class ContactsResourceTest {assertEquals(HttpMethod.DELETE, tx.lastRequest().method());}+ @Test+ void listBlockedGetsSessionWideRoute() {+ tx.respond(200, "[\"[email protected]\",\"[email protected]\"]");+ List<String> res = client.contacts.listBlocked("s");+ // Session-wide: no contact id in the path, and not the /contacts list route.+ assertEquals("http://h/api/sessions/s/contacts/blocked", tx.lastRequest().url());+ assertEquals(HttpMethod.GET, tx.lastRequest().method());+ assertNull(tx.lastRequest().body());+ assertEquals(List.of("[email protected]", "[email protected]"), res);+ }+@Testvoid addressbookUpsertAndDelete() {tx.respond(200, "{\"success\":true}");diff --git a/sdk/javascript/src/resources/contacts.ts b/sdk/javascript/src/resources/contacts.tsindex fb8693e75..ddf114130 100644--- a/sdk/javascript/src/resources/contacts.ts+++ b/sdk/javascript/src/resources/contacts.ts@@ -113,4 +113,17 @@ export class ContactsResource {path: `/api/sessions/${encodeSegment(sessionId)}/contacts/${encodeSegment(contactId)}/block`,});}++ /**+ * List the JIDs this account has blocked.+ *+ * Session-wide, so it takes no contact id — unlike {@link block} and {@link unblock}, which act on+ * one contact. Resolves a bare array of ids, not contact records.+ */+ listBlocked(sessionId: string): Promise<string[]> {+ return this.client.request<string[]>({+ method: 'GET',+ path: `/api/sessions/${encodeSegment(sessionId)}/contacts/blocked`,+ });+ }}diff --git a/sdk/javascript/test/resources.test.ts b/sdk/javascript/test/resources.test.tsindex 3f4b5d9d4..efeedaed2 100644--- a/sdk/javascript/test/resources.test.ts+++ b/sdk/javascript/test/resources.test.ts@@ -196,6 +196,17 @@ describe('ContactsResource — exact paths', () => {expect(t.lastCall!.method).toBe('DELETE');});+ it('listBlocked — GET the session-wide blocked list, no contact id and no body', async () => {+ const t = new MockTransport().on('GET', /\/contacts\/blocked$/, { body: ['[email protected]', '[email protected]'] });+ const res = await client(t).contacts.listBlocked('s');++ expect(t.lastCall!.method).toBe('GET');+ // Session-wide: no contact id in the path, and not the /contacts list route either.+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s/contacts/blocked');+ expect(t.lastCall!.body).toBeUndefined();+ expect(res).toEqual(['[email protected]', '[email protected]']);+ });+it('profilePictures batch-resolves ids via the ids query param', async () => {const t = new MockTransport().on('GET', /\/contacts\/profile-pictures$/, {body: { pictures: { '[email protected]': 'http://p/a', '[email protected]': null } },diff --git a/sdk/php/src/Resources/ContactsResource.php b/sdk/php/src/Resources/ContactsResource.phpindex 19482e1e2..f1ec168e3 100644--- a/sdk/php/src/Resources/ContactsResource.php+++ b/sdk/php/src/Resources/ContactsResource.php@@ -100,4 +100,17 @@ class ContactsResource{return $this->http->request('DELETE', "/api/sessions/{$this->http->encodeSegment($sessionId)}/contacts/{$this->http->encodeSegment($contactId)}/block");}++ /**+ * List the JIDs this account has blocked.+ *+ * Session-wide, so it takes no contact id — unlike block() and unblock(), which act on one+ * contact. Returns a bare list of ids, not contact records.+ *+ * @return array<int,string>+ */+ public function listBlocked(string $sessionId): array+ {+ return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/contacts/blocked");+ }}diff --git a/sdk/php/tests/ResourcesTest.php b/sdk/php/tests/ResourcesTest.phpindex 834d46b29..67e18b4bf 100644--- a/sdk/php/tests/ResourcesTest.php+++ b/sdk/php/tests/ResourcesTest.php@@ -174,6 +174,19 @@ class ResourcesTest extends TestCase$this->assertSame('DELETE', $backend->calls()[1]['method']);}+ public function testListBlockedGetsSessionWideRoute(): void+ {+ $backend = (new MockBackend())->on(200, ['[email protected]', '[email protected]']);+ $client = $backend->makeClient();+ $res = $client->contacts->listBlocked('s');+ $call = $backend->lastCall();+ $this->assertSame('GET', $call['method']);+ // Session-wide: no contact id in the path, and not the /contacts list route.+ $this->assertSame('/api/sessions/s/contacts/blocked', $call['path']);+ $this->assertNull($call['body']);+ $this->assertSame(['[email protected]', '[email protected]'], $res);+ }+public function testProfilePicturesBatchResolvesIdsQuery(): void{$backend = (new MockBackend())->on(200, ['pictures' => ['[email protected]' => 'http://p/a', '[email protected]' => null]]);diff --git a/sdk/python/openwa/resources/contacts.py b/sdk/python/openwa/resources/contacts.pyindex 0bcf9ea40..41f6a2a97 100644--- a/sdk/python/openwa/resources/contacts.py+++ b/sdk/python/openwa/resources/contacts.py@@ -72,3 +72,11 @@ class ContactsResource:def unblock(self, session_id: str, contact_id: str) -> SuccessResult:return self._http.request("DELETE", f"/api/sessions/{quote_segment(session_id)}/contacts/{quote_segment(contact_id)}/block")++ def list_blocked(self, session_id: str) -> list[str]:+ """List the JIDs this account has blocked.++ Session-wide, so it takes no contact id — unlike ``block`` and ``unblock``, which act on one+ contact. Returns a bare list of ids, not contact records.+ """+ return self._http.request("GET", f"/api/sessions/{quote_segment(session_id)}/contacts/blocked")diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.pyindex 78f9bfd13..532da405f 100644--- a/sdk/python/tests/test_sdk.py+++ b/sdk/python/tests/test_sdk.py@@ -488,6 +488,17 @@ class TestContacts:client.contacts.unblock("s", "[email protected]")assert backend.calls[-1].method == "DELETE"+ def test_list_blocked_gets_session_wide_route(self):+ backend = MockBackend().on("GET", "/contacts/blocked", body=["[email protected]", "[email protected]"])+ client = make_client(backend)+ res = client.contacts.list_blocked("s")+ call = backend.calls[-1]+ assert call.method == "GET"+ # Session-wide: no contact id in the path, and not the /contacts list route.+ assert call.url.endswith("/api/sessions/s/contacts/blocked")+ assert call.body is None+ assert res == ["[email protected]", "[email protected]"]+def test_profile_pictures_batch_resolves_ids_query(self):backend = MockBackend().on("GET", "/contacts/profile-pictures", body={"pictures": {"[email protected]": "http://p/a", "[email protected]": None}