Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
feat(sdk): expose voice status in all five SDKs
Yudhi Armyndharisd808eb1960b0
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 3cd0125a0..e7162f88f 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -9,6 +9,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0### Added+- **Voice status.** `POST /api/sessions/:sessionId/status/send-voice` posts an audio status as a+ voice note on both engines. It carries no caption, because WhatsApp has nowhere to render one on a+ status voice note.++ On whatsapp-web.js the send sets `sendAudioAsVoice`, which becomes `isPtt` in the page and is the+ only thing separating a voice-note bubble from an audio file; on Baileys the content is+ `{ audio, ptt: true }`, and because Baileys keys its coloured-status handling off exactly that+ combination, `backgroundColor` applies here as it does for a text status.++ Neither engine transcodes, and WhatsApp plays a status voice note only as Ogg/Opus, so the+ mimetype defaults to it and the media conversion endpoint is what produces the bytes.++ `Status.type` gains a `voice` member. Before this, the read-back mapped only images and videos and+ collapsed everything else to `text`, so an incoming voice status was reported as a text status —+ one with audio attached and a type saying otherwise. Existing values are unchanged; clients that+ switch on `type` should treat an unrecognised value as they already treat any other.++- **Server-side media conversion, and `ffmpeg` in the image.** WhatsApp renders a playablevoice-note bubble only for Ogg/Opus. Nothing in the pipeline transcoded, so posting MP3 bytes to`send-audio` with `ptt: true` sent them as they were — labelled `audio/ogg; codecs=opus`, becausediff --git a/sdk/README.md b/sdk/README.mdindex 7dee2957d..061509ec6 100644--- a/sdk/README.md+++ b/sdk/README.md@@ -33,7 +33,7 @@ All five SDKs expose the same fluent resource surface:| `labels` | list, get, forChat, addToChat, removeFromChat _(WhatsApp Business)_ || `channels` | list, get, messages, subscribe, unsubscribe _(Newsletters)_ || `catalog` | info, products, product, sendProduct, sendCatalog _(WhatsApp Business)_ |-| `status` | list, fromContact, media, sendText, sendImage, sendVideo, delete _(Stories)_ |+| `status` | list, fromContact, media, sendText, sendImage, sendVideo, sendVoice, delete _(Stories)_ || `search` | search _(Operator)_ || `templates`| list, get, create, update, delete || `profile` | setProfileName, setProfileStatus, setProfilePicture _(OPERATOR)_ |diff --git a/sdk/go/routing_test.go b/sdk/go/routing_test.goindex b1eefbe2e..f9ea9bc4b 100644--- a/sdk/go/routing_test.go+++ b/sdk/go/routing_test.go@@ -115,6 +115,7 @@ func TestRouting(t *testing.T) {{"Status.SendText", func(c *Client) { c.Status.SendText(ctx, "s1", SendTextStatusRequest{}) }, "POST", "/api/sessions/s1/status/send-text"},{"Status.SendImage", func(c *Client) { c.Status.SendImage(ctx, "s1", SendImageStatusRequest{}) }, "POST", "/api/sessions/s1/status/send-image"},{"Status.SendVideo", func(c *Client) { c.Status.SendVideo(ctx, "s1", SendVideoStatusRequest{}) }, "POST", "/api/sessions/s1/status/send-video"},+ {"Status.SendVoice", func(c *Client) { c.Status.SendVoice(ctx, "s1", SendVoiceStatusRequest{}) }, "POST", "/api/sessions/s1/status/send-voice"},{"Status.Delete", func(c *Client) { c.Status.Delete(ctx, "s1", "st1") }, "DELETE", "/api/sessions/s1/status/st1"},{"Labels.List", func(c *Client) { c.Labels.List(ctx, "s1") }, "GET", "/api/sessions/s1/labels"},diff --git a/sdk/go/status.go b/sdk/go/status.goindex 0ee973a9c..2bf5c45e5 100644--- a/sdk/go/status.go+++ b/sdk/go/status.go@@ -52,6 +52,11 @@ func (s *StatusService) SendVideo(ctx context.Context, sessionID string, body Sereturn s.send(ctx, sessionID, "/send-video", body)}+// SendVoice posts an audio status as a voice note. Requires an OPERATOR-level key.+func (s *StatusService) SendVoice(ctx context.Context, sessionID string, body SendVoiceStatusRequest) (*StatusResult, error) {+ return s.send(ctx, sessionID, "/send-voice", body)+}+func (s *StatusService) send(ctx context.Context, sessionID, suffix string, body any) (*StatusResult, error) {var out StatusResulterr := s.client.do(ctx, "POST", s.base(sessionID)+suffix, nil, body, &out)diff --git a/sdk/go/types_status.go b/sdk/go/types_status.goindex 8bf8ec3c3..d43224f83 100644--- a/sdk/go/types_status.go+++ b/sdk/go/types_status.go@@ -78,3 +78,14 @@ type SendVideoStatusRequest struct {Recipients []string `json:"recipients,omitempty"`Caption string `json:"caption,omitempty"`}++// SendVoiceStatusRequest posts an audio status as a voice note. It carries no+// caption: WhatsApp has nowhere to render one on a status voice note.+//+// Audio.Mimetype defaults to "audio/ogg; codecs=opus", the only format WhatsApp+// plays as a status voice note. Neither engine transcodes — produce those bytes+// with MediaService.ConvertVoice.+type SendVoiceStatusRequest struct {+ Audio StatusMediaInput `json:"audio"`+ Recipients []string `json:"recipients,omitempty"`+}diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendVoiceStatusRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendVoiceStatusRequest.javanew file mode 100644index 000000000..7c8495ead--- /dev/null+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendVoiceStatusRequest.java@@ -0,0 +1,38 @@+package com.rmyndharis.openwa.model;++import java.util.List;++/**+ * Request body for posting an audio status as a voice note. The server expects a nested+ * {@code { audio: {...} }} body.+ *+ * <p>There is no caption: WhatsApp has nowhere to render one on a status voice note. The audio+ * mimetype defaults to {@code audio/ogg; codecs=opus}, the only format WhatsApp plays as one —+ * neither engine transcodes, so produce those bytes with {@code MediaResource.convertVoice}.+ */+public record SendVoiceStatusRequest(StatusMediaInput audio, List<String> recipients) {+ public static Builder builder() {+ return new Builder();+ }++ public static final class Builder {+ private StatusMediaInput audio;+ private List<String> recipients;++ /** Media payload: provide {@code url} OR {@code base64}. */+ public Builder audio(StatusMediaInput v) {+ this.audio = v;+ return this;+ }++ /** Required on the Baileys engine (absent/empty yields 400); omit on whatsapp-web.js. */+ public Builder recipients(List<String> v) {+ this.recipients = v;+ return this;+ }++ public SendVoiceStatusRequest build() {+ return new SendVoiceStatusRequest(audio, recipients);+ }+ }+}diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/StatusResource.java b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/StatusResource.javaindex a5520396c..c312d9f53 100644--- a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/StatusResource.java+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/StatusResource.java@@ -8,6 +8,7 @@ import com.rmyndharis.openwa.http.HttpMethod;import com.rmyndharis.openwa.model.SendImageStatusRequest;import com.rmyndharis.openwa.model.SendTextStatusRequest;import com.rmyndharis.openwa.model.SendVideoStatusRequest;+import com.rmyndharis.openwa.model.SendVoiceStatusRequest;import com.rmyndharis.openwa.model.StatusListResult;import com.rmyndharis.openwa.model.StatusResult;@@ -81,6 +82,19 @@ public final class StatusResource {StatusResult.class);}+ /**+ * Post an audio status as a voice note. WhatsApp plays one only as Ogg/Opus and neither engine+ * transcodes, so convert first with {@code MediaResource.convertVoice}. Requires an OPERATOR key.+ */+ public StatusResult sendVoice(String sessionId, SendVoiceStatusRequest body) {+ return client.request(+ HttpMethod.POST,+ "/api/sessions/" + encodeSegment(sessionId) + "/status/send-voice",+ null,+ body,+ StatusResult.class);+ }+/** Delete a status update by id. */public void delete(String sessionId, String statusId) {client.requestVoid(diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/StatusResourceTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/StatusResourceTest.javaindex eb219449f..45708c71a 100644--- a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/StatusResourceTest.java+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/StatusResourceTest.java@@ -2,6 +2,7 @@ package com.rmyndharis.openwa.resources;import static org.junit.jupiter.api.Assertions.assertArrayEquals;import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertFalse;import static org.junit.jupiter.api.Assertions.assertThrows;import static org.junit.jupiter.api.Assertions.assertTrue;@@ -13,6 +14,7 @@ import com.rmyndharis.openwa.http.HttpMethod;import com.rmyndharis.openwa.model.SendImageStatusRequest;import com.rmyndharis.openwa.model.SendTextStatusRequest;import com.rmyndharis.openwa.model.SendVideoStatusRequest;+import com.rmyndharis.openwa.model.SendVoiceStatusRequest;import com.rmyndharis.openwa.model.StatusMediaInput;import com.rmyndharis.openwa.model.StatusRecord;import com.rmyndharis.openwa.support.MockTransport;@@ -117,6 +119,22 @@ class StatusResourceTest {assertTrue(tx.lastRequest().body().contains("AAAA"));}+ /** A voice status wraps its media under `audio` and carries no caption. */+ @Test+ void sendVoicePostsAudioWrapperWithoutCaption() {+ tx.respond(200, "{\"statusId\":\"st4\",\"timestamp\":\"2026-01-01T00:00:00Z\",\"expiresAt\":\"2026-01-02T00:00:00Z\"}");+ status.sendVoice(+ "s",+ SendVoiceStatusRequest.builder()+ .audio(StatusMediaInput.builder().base64("T2dnUw==").build())+ .recipients(List.of("[email protected]"))+ .build());+ assertEquals("http://h/api/sessions/s/status/send-voice", tx.lastRequest().url());+ assertEquals(HttpMethod.POST, tx.lastRequest().method());+ assertTrue(tx.lastRequest().body().contains("\"audio\""));+ assertFalse(tx.lastRequest().body().contains("caption"));+ }+@Testvoid deleteEncodesStatusId() {tx.respond(204, "");diff --git a/sdk/javascript/src/resources/status.ts b/sdk/javascript/src/resources/status.tsindex 1e578049c..077bb827e 100644--- a/sdk/javascript/src/resources/status.ts+++ b/sdk/javascript/src/resources/status.ts@@ -13,6 +13,7 @@ import type {SendImageStatusRequest,SendTextStatusRequest,SendVideoStatusRequest,+ SendVoiceStatusRequest,StatusRecord,StatusResult,} from '../types.js';@@ -71,6 +72,20 @@ export class StatusResource {});}+ /**+ * Post an audio status as a voice note. No caption: WhatsApp has nowhere to render one.+ *+ * WhatsApp plays a status voice note only as Ogg/Opus and neither engine transcodes, so convert+ * first with `media.convertVoice` and post the base64 it returns. Requires an OPERATOR key.+ */+ sendVoice(sessionId: string, body: SendVoiceStatusRequest): Promise<StatusResult> {+ return this.client.request<StatusResult>({+ method: 'POST',+ path: `/api/sessions/${encodeSegment(sessionId)}/status/send-voice`,+ body,+ });+ }+/** Delete a status update by id. */delete(sessionId: string, statusId: string): Promise<void> {return this.client.request<void>({diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.tsindex bc84dda1b..107cd9632 100644--- a/sdk/javascript/src/types.ts+++ b/sdk/javascript/src/types.ts@@ -837,6 +837,18 @@ export interface SendVideoStatusRequest {caption?: string;}+/**+ * A voice status carries no caption — WhatsApp has nowhere to render one on a status voice note.+ *+ * `audio.mimetype` defaults to `audio/ogg; codecs=opus`, which is the only format WhatsApp plays as a+ * status voice note. Neither engine transcodes, so produce those bytes with `media.convertVoice`.+ */+export interface SendVoiceStatusRequest {+ audio: StatusMediaInput;+ /** Recipient JIDs. Required on the Baileys engine (absent/empty → 400); omit on whatsapp-web.js, which broadcasts instead. */+ recipients?: string[];+}+// ── Health ────────────────────────────────────────────────────────export interface HealthResponse {diff --git a/sdk/javascript/test/resources.test.ts b/sdk/javascript/test/resources.test.tsindex ab4aea63e..a0f969e7c 100644--- a/sdk/javascript/test/resources.test.ts+++ b/sdk/javascript/test/resources.test.ts@@ -243,6 +243,16 @@ describe('StatusResource — nested media bodies', () => {expect(t.lastCall!.body).toEqual({ video: { url: 'http://vid' }, recipients: ['[email protected]'] });});+ // A voice status wraps its media under `audio` and carries no caption at all.+ it('sendVoice forwards the audio wrapper to send-voice', async () => {+ const t = new MockTransport().on('POST', /\/status\/send-voice$/, {+ body: { statusId: 's3', timestamp: '2025-01-01T00:00:00.000Z', expiresAt: '2025-01-02T00:00:00.000Z' },+ });+ await client(t).status.sendVoice('s', { audio: { base64: 'T2dnUw==' }, recipients: ['[email protected]'] });+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s/status/send-voice');+ expect(t.lastCall!.body).toEqual({ audio: { base64: 'T2dnUw==' }, recipients: ['[email protected]'] });+ });+it('votePoll posts the option texts', async () => {const t = new MockTransport().on('POST', /\/messages\/vote-poll$/, { body: { success: true } });await client(t).messages.votePoll('s', { chatId: 'c1', pollMessageId: 'p1', options: ['Pizza'] });diff --git a/sdk/php/src/Resources/StatusResource.php b/sdk/php/src/Resources/StatusResource.phpindex 8c377fb93..ce9a6cd4c 100644--- a/sdk/php/src/Resources/StatusResource.php+++ b/sdk/php/src/Resources/StatusResource.php@@ -76,6 +76,20 @@ class StatusResourcereturn $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/status/send-video", [], $body);}+ /**+ * Post an audio status as a voice note (OPERATOR). The body takes an `audio` wrapper and an+ * optional `recipients` list; it carries no caption, since WhatsApp has nowhere to render one+ * on a status voice note. WhatsApp plays one only as Ogg/Opus and neither engine transcodes —+ * convert first via MediaResource::convertVoice.+ *+ * @param array<string,mixed> $body+ * @return array<string,mixed>+ */+ public function sendVoice(string $sessionId, array $body): array+ {+ return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/status/send-voice", [], $body);+ }+public function delete(string $sessionId, string $statusId): void{$this->http->request('DELETE', "/api/sessions/{$this->http->encodeSegment($sessionId)}/status/{$this->http->encodeSegment($statusId)}");diff --git a/sdk/php/tests/ResourcesTest.php b/sdk/php/tests/ResourcesTest.phpindex 5deb5c86a..d04763053 100644--- a/sdk/php/tests/ResourcesTest.php+++ b/sdk/php/tests/ResourcesTest.php@@ -294,6 +294,7 @@ class ResourcesTest extends TestCase$backend->on(200, ['statusId' => 's1', 'timestamp' => '2025-01-01T00:00:00.000Z', 'expiresAt' => '2025-01-02T00:00:00.000Z']);$backend->on(200, ['statusId' => 's2', 'timestamp' => '2025-01-01T00:00:00.000Z', 'expiresAt' => '2025-01-02T00:00:00.000Z']);$backend->on(200, ['statusId' => 's3', 'timestamp' => '2025-01-01T00:00:00.000Z', 'expiresAt' => '2025-01-02T00:00:00.000Z']);+ $backend->on(200, ['statusId' => 's4', 'timestamp' => '2025-01-01T00:00:00.000Z', 'expiresAt' => '2025-01-02T00:00:00.000Z']);$client = $backend->makeClient();// Server requires `recipients` on every status post; media posts use a nested {image|video:{...}} body.$client->status->sendText('s', ['text' => 'hi', 'recipients' => ['[email protected]']]);@@ -302,6 +303,10 @@ class ResourcesTest extends TestCase$this->assertSame(['image' => ['url' => 'http://img'], 'recipients' => ['[email protected]'], 'caption' => 'c'], $backend->lastCall()['body']);$client->status->sendVideo('s', ['video' => ['url' => 'http://vid'], 'recipients' => ['[email protected]']]);$this->assertSame(['video' => ['url' => 'http://vid'], 'recipients' => ['[email protected]']], $backend->lastCall()['body']);+ // A voice status wraps its media under `audio` and carries no caption.+ $client->status->sendVoice('s', ['audio' => ['base64' => 'T2dnUw=='], 'recipients' => ['[email protected]']]);+ $this->assertSame('/api/sessions/s/status/send-voice', $backend->lastCall()['path']);+ $this->assertSame(['audio' => ['base64' => 'T2dnUw=='], 'recipients' => ['[email protected]']], $backend->lastCall()['body']);}public function testVotePollPostsOptionTexts(): voiddiff --git a/sdk/python/openwa/resources/status.py b/sdk/python/openwa/resources/status.pyindex 033c1b278..4bf842ef7 100644--- a/sdk/python/openwa/resources/status.py+++ b/sdk/python/openwa/resources/status.py@@ -13,6 +13,7 @@ from ..types import (SendImageStatusRequest,SendTextStatusRequest,SendVideoStatusRequest,+ SendVoiceStatusRequest,StatusMedia,StatusRecord,StatusResult,@@ -48,5 +49,13 @@ class StatusResource:def send_video(self, session_id: str, body: SendVideoStatusRequest) -> StatusResult:return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/status/send-video", body=body)+ def send_voice(self, session_id: str, body: SendVoiceStatusRequest) -> StatusResult:+ """Post an audio status as a voice note (OPERATOR).++ WhatsApp plays a status voice note only as Ogg/Opus and neither engine transcodes, so+ convert first with ``media.convert_voice`` and post the base64 it returns.+ """+ return self._http.request("POST", f"/api/sessions/{quote_segment(session_id)}/status/send-voice", body=body)+def delete(self, session_id: str, status_id: str) -> None:self._http.request("DELETE", f"/api/sessions/{quote_segment(session_id)}/status/{quote_segment(status_id)}")diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.pyindex 2299a5b86..26e3fb2ce 100644--- a/sdk/python/openwa/types.py+++ b/sdk/python/openwa/types.py@@ -825,6 +825,19 @@ class SendVideoStatusRequest(TypedDict, total=False):caption: str+class SendVoiceStatusRequest(TypedDict, total=False):+ """Post an audio status as a voice note.++ No caption: WhatsApp has nowhere to render one on a status voice note. ``audio.mimetype``+ defaults to ``audio/ogg; codecs=opus``, the only format WhatsApp plays as one — neither engine+ transcodes, so produce those bytes with ``media.convert_voice``.+ """++ audio: StatusMediaInput+ #: Required on the Baileys engine (absent/empty -> 400); omit on whatsapp-web.js.+ recipients: list[str]++# ── Health ────────────────────────────────────────────────────────diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.pyindex 1d2e4f595..9e4691707 100644--- a/sdk/python/tests/test_sdk.py+++ b/sdk/python/tests/test_sdk.py@@ -516,6 +516,7 @@ class TestStatus:backend = MockBackend()backend.on("POST", "/status/send-image", body={"statusId": "s1"})backend.on("POST", "/status/send-video", body={"statusId": "s2"})+ backend.on("POST", "/status/send-voice", body={"statusId": "s3"})client = make_client(backend)# Server requires a nested {image|video:{...}} body, not flat media fields,# plus a required recipients list.@@ -523,6 +524,11 @@ class TestStatus:assert backend.calls[-1].body == {"image": {"url": "http://img"}, "recipients": ["[email protected]"], "caption": "hi"}client.status.send_video("s", {"video": {"url": "http://vid"}, "recipients": ["[email protected]"]})assert backend.calls[-1].body == {"video": {"url": "http://vid"}, "recipients": ["[email protected]"]}+ # A voice status takes an `audio` wrapper and carries no caption — WhatsApp has nowhere to+ # render one on a status voice note.+ client.status.send_voice("s", {"audio": {"base64": "T2dnUw=="}, "recipients": ["[email protected]"]})+ assert backend.last_call.url == "http://localhost:2785/api/sessions/s/status/send-voice"+ assert backend.calls[-1].body == {"audio": {"base64": "T2dnUw=="}, "recipients": ["[email protected]"]}def test_vote_poll_posts_option_texts(self):backend = MockBackend().on("POST", "/messages/vote-poll", body={"success": True})