Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(sdk): expose the account's own presence route in all five clients

Yudhi Armyndhariscddbcc0c2bee
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 761d120dd..583d5f18e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `POST /sessions/:sessionId/calls/link` generates a shareable WhatsApp call link on both engines, returning the finished `https://call.whatsapp.com/…` URL; a WhatsApp-side failure answers `403` rather than a success carrying an empty link.
- `DELETE /sessions/:sessionId/profile/picture` removes the account profile picture on both engines; removing one that is already absent is a no-op answering `200`, so the call is safe to repeat.
- `docs-29-counts.spec.ts` binds every count-shaped claim in `docs/29` to the capability matrix, so a figure restated in the intro, the architecture prose, a mermaid node or a section heading cannot drift from the source it restates.
+- The JavaScript, Python, PHP, Go and Java SDKs expose `PUT /sessions/:id/presence`, which sets the account's own global presence. The gateway has published the route since v0.15.0 with no client counterpart, so a typed client had to fall back to a raw request. It is the account's presence, not a chat's — the per-chat typing and recording states are unchanged on the chats resource.
### Fixed
diff --git a/docs/18-sdk-design.md b/docs/18-sdk-design.md
index aa63007e6..781762463 100644
--- a/docs/18-sdk-design.md
+++ b/docs/18-sdk-design.md
@@ -28,7 +28,7 @@ All five SDKs expose the same fluent surface:
| Resource | Methods |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| `sessions` | list, get, getConfig, updateConfig, create, delete, start, stop, logout, forceKill, getQrCode, requestPairingCode, stats |
+| `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 |
| `groups` | list, get, create, joinInfo, joinGroup, add/remove/promote/demoteParticipants, setSubject, setDescription, getGroupSettings, updateGroupSettings, leave, getPicture, setPicture, deletePicture, inviteCode, revokeInviteCode |
@@ -138,6 +138,7 @@ The top-level client also exposes:
| `forceKill` | `forceKill(id)` | Force-kill a stuck session (SIGKILL + teardown). **OPERATOR** |
| `getQrCode` | `getQrCode(id)` | Get the current QR code for authentication (live from the engine). **OPERATOR** |
| `requestPairingCode` | `requestPairingCode(id, body)` | Request an 8-character pairing code for phone-based login. **OPERATOR** |
+| `setOnlinePresence` | `setOnlinePresence(id, body)` | Set the account's own global presence (appear online or offline). **OPERATOR** |
| `stats` | `stats()` | Aggregate statistics across the key's sessions. |
#### `messages`
@@ -499,6 +500,7 @@ Resources are accessed as properties on the client (e.g. `client.messages`). All
| `force_kill` | `force_kill(session_id) -> SessionResponse` | Force-terminate a session. **OPERATOR** |
| `get_qr_code` | `get_qr_code(session_id) -> QrCodeResponse` | Fetch the login QR code. **OPERATOR** |
| `request_pairing_code` | `request_pairing_code(session_id, body) -> PairingCodeResponse` | Request a phone-number pairing code. **OPERATOR** |
+| `set_online_presence` | `set_online_presence(session_id, body) -> SuccessResult` | Set the account's own global presence (appear online or offline). **OPERATOR** |
| `stats` | `stats() -> SessionStatsOverview` | Session statistics overview. |
#### `client.messages`
@@ -831,6 +833,7 @@ All payloads are associative arrays; all listed methods are synchronous and retu
| `forceKill` | `forceKill(string $id): array` | Force-kill a session. **OPERATOR** |
| `getQrCode` | `getQrCode(string $id): array` | Fetch the current QR code. **OPERATOR** |
| `requestPairingCode` | `requestPairingCode(string $id, array $body): array` | Request a phone-pairing code. **OPERATOR** |
+| `setOnlinePresence` | `setOnlinePresence(string $id, array $body): array` | Set the account's own global presence (appear online or offline). **OPERATOR** |
| `stats` | `stats(): array` | `GET /api/sessions/stats/overview`. |
#### `messages`
diff --git a/sdk/README.md b/sdk/README.md
index ba754ed04..fa48e5eff 100644
--- a/sdk/README.md
+++ b/sdk/README.md
@@ -24,7 +24,7 @@ All five SDKs expose the same fluent resource surface:
| Resource | Methods |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| `sessions` | list, get, getConfig, updateConfig, create, delete, start, stop, logout, forceKill, getQrCode, requestPairingCode, stats |
+| `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 |
| `groups` | list, get, create, joinGroup, joinInfo, add/remove/promote/demoteParticipants, setSubject, setDescription, get/updateGroupSettings, leave, getPicture, setPicture, deletePicture, inviteCode, revokeInviteCode |
diff --git a/sdk/go/routing_test.go b/sdk/go/routing_test.go
index f9ea9bc4b..dc98c8ebf 100644
--- a/sdk/go/routing_test.go
+++ b/sdk/go/routing_test.go
@@ -27,6 +27,7 @@ func TestRouting(t *testing.T) {
{"Sessions.ForceKill", func(c *Client) { c.Sessions.ForceKill(ctx, "s1") }, "POST", "/api/sessions/s1/force-kill"},
{"Sessions.QRCode", func(c *Client) { c.Sessions.QRCode(ctx, "s1") }, "GET", "/api/sessions/s1/qr"},
{"Sessions.RequestPairingCode", func(c *Client) { c.Sessions.RequestPairingCode(ctx, "s1", RequestPairingCodeRequest{}) }, "POST", "/api/sessions/s1/pairing-code"},
+ {"Sessions.SetOnlinePresence", func(c *Client) { c.Sessions.SetOnlinePresence(ctx, "s1", SetOwnPresenceRequest{}) }, "PUT", "/api/sessions/s1/presence"},
{"Sessions.Stats", func(c *Client) { c.Sessions.Stats(ctx) }, "GET", "/api/sessions/stats/overview"},
{"Messages.List", func(c *Client) { c.Messages.List(ctx, "s1", nil) }, "GET", "/api/sessions/s1/messages"},
diff --git a/sdk/go/sessions.go b/sdk/go/sessions.go
index 17bdde4c3..ed92a66e7 100644
--- a/sdk/go/sessions.go
+++ b/sdk/go/sessions.go
@@ -136,3 +136,19 @@ func (s *SessionsService) Stats(ctx context.Context) (*SessionStatsOverview, err
}
return &out, nil
}
+
+// SetOnlinePresence sets the account's own global presence — appear online, or offline.
+//
+// Available=false hands notifications back to the phone: a linked device that stays online
+// suppresses the phone's own alerts. This is the ACCOUNT's presence, not a chat's — see
+// ChatsService.SendState for per-chat typing/recording states.
+func (s *SessionsService) SetOnlinePresence(
+ ctx context.Context, sessionID string, body SetOwnPresenceRequest,
+) (*SuccessResult, error) {
+ var out SuccessResult
+ err := s.client.do(ctx, "PUT", "/api/sessions/"+pathEscape(sessionID)+"/presence", nil, body, &out)
+ if err != nil {
+ return nil, err
+ }
+ return &out, nil
+}
diff --git a/sdk/go/types_chat.go b/sdk/go/types_chat.go
index b59eab14f..2d3ef2b15 100644
--- a/sdk/go/types_chat.go
+++ b/sdk/go/types_chat.go
@@ -13,6 +13,12 @@ type ChatSummary struct {
Kind string `json:"kind"`
}
+// SetOwnPresenceRequest is the body for SessionsService.SetOnlinePresence. Available reports
+// whether the account should appear online (true) or offline (false).
+type SetOwnPresenceRequest struct {
+ Available bool `json:"available"`
+}
+
// MarkChatRequest marks a chat read/unread.
type MarkChatRequest struct {
ChatID string `json:"chatId"`
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/SetOwnPresenceRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SetOwnPresenceRequest.java
new file mode 100644
index 000000000..2f0e88b39
--- /dev/null
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SetOwnPresenceRequest.java
@@ -0,0 +1,22 @@
+package com.rmyndharis.openwa.model;
+
+/** Request body for setting the account's own global presence. */
+public record SetOwnPresenceRequest(boolean available) {
+ public static Builder builder() {
+ return new Builder();
+ }
+
+ public static final class Builder {
+ private boolean available;
+
+ /** {@code true} to appear online; {@code false} to appear offline. */
+ public Builder available(boolean v) {
+ this.available = v;
+ return this;
+ }
+
+ public SetOwnPresenceRequest build() {
+ return new SetOwnPresenceRequest(available);
+ }
+ }
+}
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/SessionsResource.java b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/SessionsResource.java
index d3ae3574d..0b99be421 100644
--- a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/SessionsResource.java
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/SessionsResource.java
@@ -12,6 +12,8 @@ import com.rmyndharis.openwa.model.RequestPairingCodeRequest;
import com.rmyndharis.openwa.model.SessionConfig;
import com.rmyndharis.openwa.model.SessionResponse;
import com.rmyndharis.openwa.model.SessionStatsOverview;
+import com.rmyndharis.openwa.model.SetOwnPresenceRequest;
+import com.rmyndharis.openwa.model.SuccessResult;
import com.rmyndharis.openwa.model.UpdateSessionConfigRequest;
import java.util.List;
@@ -108,4 +110,16 @@ public final class SessionsResource {
public SessionStatsOverview stats() {
return client.request(HttpMethod.GET, "/api/sessions/stats/overview", null, null, SessionStatsOverview.class);
}
+
+ /**
+ * Set the account's own global presence — appear online, or offline.
+ *
+ * <p>{@code available: false} hands notifications back to the phone: a linked device that stays
+ * online suppresses the phone's own alerts. This is the ACCOUNT's presence, not a chat's — see
+ * {@code ChatsResource.sendState} for per-chat typing/recording states.
+ */
+ public SuccessResult setOnlinePresence(String id, SetOwnPresenceRequest body) {
+ return client.request(HttpMethod.PUT, "/api/sessions/" + encodeSegment(id) + "/presence", null, body, SuccessResult.class);
+ }
+
}
diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/SessionsResourceTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/SessionsResourceTest.java
index 6cd51af85..51488d5be 100644
--- a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/SessionsResourceTest.java
+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/SessionsResourceTest.java
@@ -7,6 +7,7 @@ import com.rmyndharis.openwa.ClientConfig;
import com.rmyndharis.openwa.OpenWAClient;
import com.rmyndharis.openwa.http.HttpMethod;
import com.rmyndharis.openwa.model.RequestPairingCodeRequest;
+import com.rmyndharis.openwa.model.SetOwnPresenceRequest;
import com.rmyndharis.openwa.support.MockTransport;
import org.junit.jupiter.api.Test;
@@ -60,4 +61,15 @@ class SessionsResourceTest {
client.sessions.stats();
assertEquals("http://h/api/sessions/stats/overview", tx.lastRequest().url());
}
+
+ @Test
+ void setOnlinePresenceSendsPutWithFlag() {
+ tx.respond(200, "{\"success\":true}");
+ client.sessions.setOnlinePresence("s", SetOwnPresenceRequest.builder().available(false).build());
+ // The account's own presence: no chat id in the path and no /subscribe suffix.
+ assertEquals("http://h/api/sessions/s/presence", tx.lastRequest().url());
+ assertEquals(HttpMethod.PUT, tx.lastRequest().method());
+ assertTrue(tx.lastRequest().body().contains("\"available\":false"));
+ }
+
}
diff --git a/sdk/javascript/src/resources/sessions.ts b/sdk/javascript/src/resources/sessions.ts
index 39d3d9c6b..404c6e174 100644
--- a/sdk/javascript/src/resources/sessions.ts
+++ b/sdk/javascript/src/resources/sessions.ts
@@ -16,6 +16,8 @@ import type {
SessionResponse,
UpdateSessionConfigRequest,
SessionStatsOverview,
+ SetOwnPresenceRequest,
+ SuccessResult,
} from '../types.js';
/** Pagination for {@link SessionsResource.list}. The server applies its own default when omitted. */
@@ -95,7 +97,10 @@ export class SessionsResource {
/** Force-kill a stuck session (SIGKILL + teardown). */
forceKill(id: string): Promise<SessionResponse> {
- return this.client.request<SessionResponse>({ method: 'POST', path: `/api/sessions/${encodeSegment(id)}/force-kill` });
+ return this.client.request<SessionResponse>({
+ method: 'POST',
+ path: `/api/sessions/${encodeSegment(id)}/force-kill`,
+ });
}
/** Get the current QR code for authentication (live from the engine, not the DB). */
@@ -119,4 +124,19 @@ export class SessionsResource {
path: '/api/sessions/stats/overview',
});
}
+
+ /**
+ * Set the account's own global presence — appear online, or offline.
+ *
+ * `available: false` hands notifications back to the phone: a linked device that stays online
+ * suppresses the phone's own alerts. This is the ACCOUNT's presence, not a chat's — see
+ * {@link ChatsResource.sendState} for per-chat typing/recording.
+ */
+ setOnlinePresence(sessionId: string, body: SetOwnPresenceRequest): Promise<SuccessResult> {
+ return this.client.request<SuccessResult>({
+ method: 'PUT',
+ path: `/api/sessions/${encodeSegment(sessionId)}/presence`,
+ body,
+ });
+ }
}
diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.ts
index 353c42da9..5790198e3 100644
--- a/sdk/javascript/src/types.ts
+++ b/sdk/javascript/src/types.ts
@@ -796,6 +796,12 @@ export interface ChatSummary {
kind?: ChatKind;
}
+/** Body for {@link SessionsResource.setOnlinePresence}. */
+export interface SetOwnPresenceRequest {
+ /** `true` = appear online; `false` = appear offline, handing notifications back to the phone. */
+ available: boolean;
+}
+
export interface MarkChatRequest {
chatId: Jid;
}
diff --git a/sdk/javascript/test/sessions.test.ts b/sdk/javascript/test/sessions.test.ts
index 88c5d4946..da3143004 100644
--- a/sdk/javascript/test/sessions.test.ts
+++ b/sdk/javascript/test/sessions.test.ts
@@ -51,4 +51,15 @@ describe('SessionsResource — exact paths', () => {
await c.sessions.stats();
expect(t.lastCall!.url).toBe('http://x/api/sessions/stats/overview');
});
+
+ it('setOnlinePresence — PUT with the availability flag', async () => {
+ const t = new MockTransport().on('PUT', /\/presence$/, { body: { success: true } });
+ await client(t).sessions.setOnlinePresence('s1', { available: false });
+
+ expect(t.lastCall!.method).toBe('PUT');
+ // The account's own presence, not a chat's: no chat id in the path and no /subscribe suffix.
+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s1/presence');
+ expect(t.lastCall!.body).toEqual({ available: false });
+ });
+
});
diff --git a/sdk/php/src/Resources/SessionsResource.php b/sdk/php/src/Resources/SessionsResource.php
index 50031920f..7c2549637 100644
--- a/sdk/php/src/Resources/SessionsResource.php
+++ b/sdk/php/src/Resources/SessionsResource.php
@@ -130,4 +130,20 @@ class SessionsResource
{
return $this->http->request('GET', '/api/sessions/stats/overview');
}
+
+ /**
+ * Set the account's own global presence — appear online, or offline.
+ *
+ * `available: false` hands notifications back to the phone: a linked device that stays online
+ * suppresses the phone's own alerts. This is the ACCOUNT's presence, not a chat's — see
+ * ChatsResource for per-chat typing/recording states.
+ *
+ * @param array{available:bool} $body
+ * @return array<string,mixed>
+ */
+ public function setOnlinePresence(string $id, array $body): array
+ {
+ return $this->http->request('PUT', "/api/sessions/{$this->http->encodeSegment($id)}/presence", [], $body);
+ }
+
}
diff --git a/sdk/php/tests/ResourcesTest.php b/sdk/php/tests/ResourcesTest.php
index d04763053..b7c83fc8a 100644
--- a/sdk/php/tests/ResourcesTest.php
+++ b/sdk/php/tests/ResourcesTest.php
@@ -55,6 +55,18 @@ class ResourcesTest extends TestCase
$this->assertStringContainsString('/sessions/stats/overview', $backend->lastCall()['url']);
}
+ public function testSetOnlinePresence(): void
+ {
+ $backend = new MockBackend();
+ $backend->on(200, ['success' => true]);
+ $client = $backend->makeClient();
+ $client->sessions->setOnlinePresence('s1', ['available' => false]);
+ // The account's own presence: no chat id in the path and no /subscribe suffix.
+ $this->assertSame('PUT', $backend->lastCall()['method']);
+ $this->assertStringEndsWith('/sessions/s1/presence', $backend->lastCall()['url']);
+ $this->assertSame(['available' => false], $backend->lastCall()['body']);
+ }
+
// ── Groups ────────────────────────────────────────────────────────
public function testGroupListGetCreate(): void
diff --git a/sdk/python/openwa/resources/sessions.py b/sdk/python/openwa/resources/sessions.py
index 60c95dfee..6f0380863 100644
--- a/sdk/python/openwa/resources/sessions.py
+++ b/sdk/python/openwa/resources/sessions.py
@@ -17,6 +17,8 @@ from ..types import (
RequestPairingCodeRequest,
SessionResponse,
SessionStatsOverview,
+ SetOwnPresenceRequest,
+ SuccessResult,
)
if TYPE_CHECKING:
@@ -104,3 +106,14 @@ class SessionsResource:
def stats(self) -> SessionStatsOverview:
"""Return the aggregate session stats overview."""
return self._http.request("GET", "/api/sessions/stats/overview")
+
+ def set_online_presence(self, session_id: str, body: SetOwnPresenceRequest) -> SuccessResult:
+ """Set the account's own global presence — appear online, or offline.
+
+ ``available: False`` hands notifications back to the phone: a linked device that stays
+ online suppresses the phone's own alerts. This is the ACCOUNT's presence, not a chat's —
+ see the chats resource for per-chat typing/recording states.
+ """
+ return self._http.request(
+ "PUT", f"/api/sessions/{quote_segment(session_id)}/presence", body=body
+ )
diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.py
index 071a53045..f287e2ff3 100644
--- a/sdk/python/openwa/types.py
+++ b/sdk/python/openwa/types.py
@@ -38,6 +38,16 @@ WebhookEvent = Literal[
]
+class SetOwnPresenceRequest(TypedDict):
+ """Body for :meth:`SessionsResource.set_online_presence`.
+
+ ``available`` is True to appear online, False to appear offline (handing notifications back
+ to the phone).
+ """
+
+ available: bool
+
+
class SuccessResult(TypedDict, total=False):
success: bool
message: str
diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.py
index a4a151fc4..4239fdbaf 100644
--- a/sdk/python/tests/test_sdk.py
+++ b/sdk/python/tests/test_sdk.py
@@ -305,6 +305,16 @@ class TestSessions:
client.sessions.stats()
assert "/sessions/stats/overview" in backend.calls[-1].url
+ def test_set_online_presence(self):
+ backend = MockBackend()
+ backend.on("PUT", "/presence", body={"success": True})
+ client = make_client(backend)
+ client.sessions.set_online_presence("s1", {"available": False})
+ # The account's own presence: no chat id in the path and no /subscribe suffix.
+ assert backend.calls[-1].method == "PUT"
+ assert backend.calls[-1].url.endswith("/sessions/s1/presence")
+ assert backend.calls[-1].body == {"available": False}
+
# ── Groups, Contacts, Webhooks, Chats, Health ──────────────────────