Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

feat(sdk): expose media conversion in all five SDKs

Yudhi Armyndharis8881cd0015c6
diff --git a/sdk/README.md b/sdk/README.md
index 986279cce..7dee2957d 100644
--- a/sdk/README.md
+++ b/sdk/README.md
@@ -38,6 +38,7 @@ All five SDKs expose the same fluent resource surface:
| `templates`| list, get, create, update, delete |
| `profile` | setProfileName, setProfileStatus, setProfilePicture _(OPERATOR)_ |
| `calls` | rejectCall _(OPERATOR)_ |
+| `media` | conversionStatus, convertVoice, convertVideo _(OPERATOR)_ |
| `health` | check, live, ready |
> ⚠️ Endpoints requiring an `OPERATOR`-level API key are noted in the inline
diff --git a/sdk/go/client.go b/sdk/go/client.go
index e9810eb92..13141e91f 100644
--- a/sdk/go/client.go
+++ b/sdk/go/client.go
@@ -69,6 +69,7 @@ type Client struct {
Auth *AuthService
Profile *ProfileService
Calls *CallsService
+ Media *MediaService
}
var localhostHosts = map[string]bool{"localhost": true, "127.0.0.1": true, "::1": true}
@@ -150,6 +151,7 @@ func New(baseURL, apiKey string, opts ...Option) (*Client, error) {
c.Auth = &AuthService{client: c}
c.Profile = &ProfileService{client: c}
c.Calls = &CallsService{client: c}
+ c.Media = &MediaService{client: c}
return c, nil
}
diff --git a/sdk/go/client_test.go b/sdk/go/client_test.go
index 5e47575d0..15712410d 100644
--- a/sdk/go/client_test.go
+++ b/sdk/go/client_test.go
@@ -1278,3 +1278,59 @@ func TestWebhookFiltersPolymorphicWireShape(t *testing.T) {
t.Fatal("caseSensitive should be omitted when unset")
}
}
+
+func TestMediaConversionStatus(t *testing.T) {
+ rt := &recordTransport{status: 200, body: `{"available":true}`}
+ c := newTestClient(t, rt)
+
+ res, err := c.Media.ConversionStatus(context.Background(), "s1")
+ if err != nil {
+ t.Fatalf("ConversionStatus: %v", err)
+ }
+ if !res.Available {
+ t.Fatalf("unexpected response: %+v", res)
+ }
+ if got, want := rt.lastReq.URL.Path, "/api/sessions/s1/media/convert"; got != want {
+ t.Fatalf("path = %q, want %q", got, want)
+ }
+ if rt.lastReq.Method != "GET" {
+ t.Fatalf("method = %q, want GET", rt.lastReq.Method)
+ }
+}
+
+func TestConvertVoice(t *testing.T) {
+ rt := &recordTransport{status: 200, body: `{"base64":"T2dnUw==","mimetype":"audio/ogg; codecs=opus","bytes":8}`}
+ c := newTestClient(t, rt)
+
+ res, err := c.Media.ConvertVoice(context.Background(), "s1", ConvertMediaInput{Base64: "SUQz"})
+ if err != nil {
+ t.Fatalf("ConvertVoice: %v", err)
+ }
+ if res.Mimetype != "audio/ogg; codecs=opus" || res.Bytes != 8 {
+ t.Fatalf("unexpected response: %+v", res)
+ }
+ if got, want := rt.lastReq.URL.Path, "/api/sessions/s1/media/convert/voice"; got != want {
+ t.Fatalf("path = %q, want %q", got, want)
+ }
+
+ // An unset URL must be omitted rather than sent as an empty string, which the
+ // server would read as a supplied-but-blank field.
+ if got := string(rt.lastRaw); got != `{"base64":"SUQz"}` {
+ t.Fatalf("body = %s, want {\"base64\":\"SUQz\"}", got)
+ }
+}
+
+func TestConvertVideo(t *testing.T) {
+ rt := &recordTransport{status: 200, body: `{"base64":"AAAA","mimetype":"video/mp4","bytes":4}`}
+ c := newTestClient(t, rt)
+
+ if _, err := c.Media.ConvertVideo(context.Background(), "s1", ConvertMediaInput{URL: "https://example.com/c.mov"}); err != nil {
+ t.Fatalf("ConvertVideo: %v", err)
+ }
+ if got, want := rt.lastReq.URL.Path, "/api/sessions/s1/media/convert/video"; got != want {
+ t.Fatalf("path = %q, want %q", got, want)
+ }
+ if got := string(rt.lastRaw); got != `{"url":"https://example.com/c.mov"}` {
+ t.Fatalf("body = %s, want the url only", got)
+ }
+}
diff --git a/sdk/go/media.go b/sdk/go/media.go
new file mode 100644
index 000000000..be5d5f60d
--- /dev/null
+++ b/sdk/go/media.go
@@ -0,0 +1,71 @@
+package openwa
+
+import "context"
+
+// MediaService converts media into the formats WhatsApp plays.
+// Backed by src/modules/media/media.controller.ts.
+type MediaService struct{ client *Client }
+
+func (s *MediaService) base(sessionID string) string {
+ return "/api/sessions/" + pathEscape(sessionID) + "/media"
+}
+
+// ConvertMediaInput carries the media to convert. Set exactly one of URL or
+// Base64; Base64 wins when both are given. No mimetype is needed — the input
+// format is read from the bytes.
+type ConvertMediaInput struct {
+ URL string `json:"url,omitempty"`
+ Base64 string `json:"base64,omitempty"`
+}
+
+// ConvertedMedia is the result, shaped for handing straight to a send call.
+type ConvertedMedia struct {
+ // Base64 holds the converted bytes, ready to use as a send call's Base64 field.
+ Base64 string `json:"base64"`
+ // Mimetype is what the bytes now are, not what they were.
+ Mimetype string `json:"mimetype"`
+ // Bytes is the decoded size, so a size check needs no decoding.
+ Bytes int64 `json:"bytes"`
+}
+
+// MediaConversionAvailability reports whether conversion can be used here.
+type MediaConversionAvailability struct {
+ Available bool `json:"available"`
+}
+
+// ConversionStatus reports whether conversion is switched on for this deployment
+// AND the ffmpeg binary can be run. Worth checking once: against a server without
+// it, a caller must convert on its own side rather than take an error per request.
+func (s *MediaService) ConversionStatus(ctx context.Context, sessionID string) (*MediaConversionAvailability, error) {
+ var out MediaConversionAvailability
+ err := s.client.do(ctx, "GET", s.base(sessionID)+"/convert", nil, nil, &out)
+ if err != nil {
+ return nil, err
+ }
+ return &out, nil
+}
+
+// ConvertVoice converts audio into a WhatsApp voice note (Ogg/Opus, mono, tuned
+// for speech). WhatsApp shows a playable mic bubble only for this format — MP3
+// bytes sent with PTT produce a voice note that will not play. Pass the returned
+// Base64 to SendAudio with PTT set. Requires an OPERATOR-level key.
+func (s *MediaService) ConvertVoice(ctx context.Context, sessionID string, in ConvertMediaInput) (*ConvertedMedia, error) {
+ var out ConvertedMedia
+ err := s.client.do(ctx, "POST", s.base(sessionID)+"/convert/voice", nil, in, &out)
+ if err != nil {
+ return nil, err
+ }
+ return &out, nil
+}
+
+// ConvertVideo converts video into an MP4 every WhatsApp client accepts: baseline
+// H.264 with AAC audio, long edge bounded at 1280, index moved to the front for
+// immediate playback. Requires an OPERATOR-level key.
+func (s *MediaService) ConvertVideo(ctx context.Context, sessionID string, in ConvertMediaInput) (*ConvertedMedia, error) {
+ var out ConvertedMedia
+ err := s.client.do(ctx, "POST", s.base(sessionID)+"/convert/video", nil, in, &out)
+ if err != nil {
+ return nil, err
+ }
+ return &out, nil
+}
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java b/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java
index c3016f7e5..1cc3ac9b8 100644
--- a/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/OpenWAClient.java
@@ -13,6 +13,7 @@ import com.rmyndharis.openwa.http.HttpResponseData;
import com.rmyndharis.openwa.http.HttpTransport;
import com.rmyndharis.openwa.model.AuthValidateResponse;
import com.rmyndharis.openwa.resources.CallsResource;
+import com.rmyndharis.openwa.resources.MediaResource;
import com.rmyndharis.openwa.resources.CatalogResource;
import com.rmyndharis.openwa.resources.ChannelsResource;
import com.rmyndharis.openwa.resources.ChatsResource;
@@ -65,6 +66,7 @@ public final class OpenWAClient {
public final HealthResource health = new HealthResource(this);
public final ProfileResource profile = new ProfileResource(this);
public final CallsResource calls = new CallsResource(this);
+ public final MediaResource media = new MediaResource(this);
public OpenWAClient(ClientConfig config) {
// ClientConfig's constructor validates baseUrl/apiKey/timeout, so config is already sound here.
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/ConvertMediaRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/ConvertMediaRequest.java
new file mode 100644
index 000000000..94c8f9897
--- /dev/null
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/ConvertMediaRequest.java
@@ -0,0 +1,17 @@
+package com.rmyndharis.openwa.model;
+
+/**
+ * Media to convert. Set exactly one of {@code url} or {@code base64}; {@code base64} wins when both
+ * are given. No mimetype is carried — the input format is read from the bytes.
+ */
+public record ConvertMediaRequest(String url, String base64) {
+ /** Convert media the server will fetch itself (SSRF-guarded). */
+ public static ConvertMediaRequest ofUrl(String url) {
+ return new ConvertMediaRequest(url, null);
+ }
+
+ /** Convert media supplied inline. */
+ public static ConvertMediaRequest ofBase64(String base64) {
+ return new ConvertMediaRequest(null, base64);
+ }
+}
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/ConvertedMedia.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/ConvertedMedia.java
new file mode 100644
index 000000000..ec2eed7fc
--- /dev/null
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/ConvertedMedia.java
@@ -0,0 +1,10 @@
+package com.rmyndharis.openwa.model;
+
+/**
+ * Converted media, shaped for handing straight to a send call.
+ *
+ * @param base64 the converted bytes, ready to use as a send call's base64
+ * @param mimetype what the bytes now are — not what they were
+ * @param bytes decoded size, so a size check needs no decoding
+ */
+public record ConvertedMedia(String base64, String mimetype, long bytes) {}
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/MediaConversionAvailability.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/MediaConversionAvailability.java
new file mode 100644
index 000000000..d566d2c7b
--- /dev/null
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/MediaConversionAvailability.java
@@ -0,0 +1,4 @@
+package com.rmyndharis.openwa.model;
+
+/** Whether server-side media conversion can be used on this deployment. */
+public record MediaConversionAvailability(boolean available) {}
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/resources/MediaResource.java b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/MediaResource.java
new file mode 100644
index 000000000..11f7ff73e
--- /dev/null
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/resources/MediaResource.java
@@ -0,0 +1,59 @@
+package com.rmyndharis.openwa.resources;
+
+import static com.rmyndharis.openwa.http.Http.encodeSegment;
+
+import com.rmyndharis.openwa.OpenWAClient;
+import com.rmyndharis.openwa.http.HttpMethod;
+import com.rmyndharis.openwa.model.ConvertMediaRequest;
+import com.rmyndharis.openwa.model.ConvertedMedia;
+import com.rmyndharis.openwa.model.MediaConversionAvailability;
+
+/** Media resource — server-side conversion into the formats WhatsApp plays. */
+public final class MediaResource {
+ private final OpenWAClient client;
+
+ public MediaResource(OpenWAClient client) {
+ this.client = client;
+ }
+
+ /**
+ * Whether conversion is switched on for this deployment AND the ffmpeg binary can be run. Worth
+ * checking once: against a server without it a caller must convert on its own side rather than
+ * take an error per request.
+ */
+ public MediaConversionAvailability conversionStatus(String sessionId) {
+ return client.request(
+ HttpMethod.GET,
+ "/api/sessions/" + encodeSegment(sessionId) + "/media/convert",
+ null,
+ null,
+ MediaConversionAvailability.class);
+ }
+
+ /**
+ * Convert audio into a WhatsApp voice note (Ogg/Opus, mono, tuned for speech). WhatsApp shows a
+ * playable mic bubble only for this format — MP3 bytes sent with ptt produce a voice note that
+ * will not play. Pass the returned base64 to sendAudio with ptt set. Requires an OPERATOR key.
+ */
+ public ConvertedMedia convertVoice(String sessionId, ConvertMediaRequest media) {
+ return client.request(
+ HttpMethod.POST,
+ "/api/sessions/" + encodeSegment(sessionId) + "/media/convert/voice",
+ null,
+ media,
+ ConvertedMedia.class);
+ }
+
+ /**
+ * Convert video into an MP4 every WhatsApp client accepts: baseline H.264 with AAC audio, long
+ * edge bounded at 1280, index moved to the front for immediate playback. Requires an OPERATOR key.
+ */
+ public ConvertedMedia convertVideo(String sessionId, ConvertMediaRequest media) {
+ return client.request(
+ HttpMethod.POST,
+ "/api/sessions/" + encodeSegment(sessionId) + "/media/convert/video",
+ null,
+ media,
+ ConvertedMedia.class);
+ }
+}
diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/MediaResourceTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/MediaResourceTest.java
new file mode 100644
index 000000000..7f2f8a2f3
--- /dev/null
+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/MediaResourceTest.java
@@ -0,0 +1,60 @@
+package com.rmyndharis.openwa.resources;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import com.rmyndharis.openwa.ClientConfig;
+import com.rmyndharis.openwa.OpenWAClient;
+import com.rmyndharis.openwa.http.HttpMethod;
+import com.rmyndharis.openwa.model.ConvertMediaRequest;
+import com.rmyndharis.openwa.model.ConvertedMedia;
+import com.rmyndharis.openwa.support.MockTransport;
+import org.junit.jupiter.api.Test;
+
+class MediaResourceTest {
+ final MockTransport tx = new MockTransport();
+ final OpenWAClient client = new OpenWAClient(
+ ClientConfig.builder().baseUrl("http://h").apiKey("k").transport(tx).build());
+
+ @Test
+ void conversionStatusHitsConvertRoot() {
+ tx.respond(200, "{\"available\":true}");
+ assertTrue(client.media.conversionStatus("s").available());
+ assertEquals("http://h/api/sessions/s/media/convert", tx.lastRequest().url());
+ assertEquals(HttpMethod.GET, tx.lastRequest().method());
+ }
+
+ @Test
+ void convertVoiceHitsVoicePathAndParsesResult() {
+ tx.respond(200, "{\"base64\":\"T2dnUw==\",\"mimetype\":\"audio/ogg; codecs=opus\",\"bytes\":8}");
+ ConvertedMedia res = client.media.convertVoice("s", ConvertMediaRequest.ofBase64("SUQz"));
+ assertEquals("http://h/api/sessions/s/media/convert/voice", tx.lastRequest().url());
+ assertEquals(HttpMethod.POST, tx.lastRequest().method());
+ assertEquals("audio/ogg; codecs=opus", res.mimetype());
+ assertEquals(8L, res.bytes());
+ }
+
+ /**
+ * The unset field must be absent, not null. The server distinguishes "not supplied" from
+ * "supplied as null" — a serialized null would be validated as a value and rejected.
+ */
+ @Test
+ void unsetFieldIsOmittedRatherThanSentAsNull() {
+ tx.respond(200, "{\"base64\":\"T2dnUw==\",\"mimetype\":\"audio/ogg; codecs=opus\",\"bytes\":8}");
+ client.media.convertVoice("s", ConvertMediaRequest.ofBase64("SUQz"));
+ assertEquals("{\"base64\":\"SUQz\"}", tx.lastRequest().body());
+
+ tx.respond(200, "{\"base64\":\"AAAA\",\"mimetype\":\"video/mp4\",\"bytes\":4}");
+ client.media.convertVideo("s", ConvertMediaRequest.ofUrl("https://example.com/c.mov"));
+ assertEquals("{\"url\":\"https://example.com/c.mov\"}", tx.lastRequest().body());
+ assertFalse(tx.lastRequest().body().contains("null"));
+ }
+
+ @Test
+ void convertVideoHitsVideoPath() {
+ tx.respond(200, "{\"base64\":\"AAAA\",\"mimetype\":\"video/mp4\",\"bytes\":4}");
+ assertEquals("video/mp4", client.media.convertVideo("s", ConvertMediaRequest.ofUrl("http://x/a.mov")).mimetype());
+ assertEquals("http://h/api/sessions/s/media/convert/video", tx.lastRequest().url());
+ }
+}
diff --git a/sdk/javascript/src/client.ts b/sdk/javascript/src/client.ts
index caaa43d6e..6655555bc 100644
--- a/sdk/javascript/src/client.ts
+++ b/sdk/javascript/src/client.ts
@@ -25,6 +25,7 @@
import { request, requestBytes, encodeSegment, warnIfInsecureHttpUrl, type BinaryResponse, type ClientConfig, type FetchLike, type RequestOptions } from './http.js';
import { CallsResource } from './resources/calls.js';
+import { MediaResource } from './resources/media.js';
import { CatalogResource } from './resources/catalog.js';
import { ChannelsResource } from './resources/channels.js';
import { ChatsResource } from './resources/chats.js';
@@ -89,6 +90,7 @@ export class OpenWAClient {
readonly search = new SearchResource(this);
readonly profile = new ProfileResource(this);
readonly calls = new CallsResource(this);
+ readonly media = new MediaResource(this);
// ── Auth ─────────────────────────────────────────────────────────
diff --git a/sdk/javascript/src/resources/media.ts b/sdk/javascript/src/resources/media.ts
new file mode 100644
index 000000000..c24c0e24f
--- /dev/null
+++ b/sdk/javascript/src/resources/media.ts
@@ -0,0 +1,54 @@
+/**
+ * Media resource — server-side conversion into the formats WhatsApp plays.
+ *
+ * Backed by `src/modules/media/media.controller.ts` (`@Controller('sessions/:sessionId/media')`).
+ * @packageDocumentation
+ */
+
+import { encodeSegment } from '../http.js';
+import type { OpenWAClient } from '../client.js';
+import type { ConvertMediaInput, ConvertedMedia, MediaConversionAvailability } from '../types.js';
+
+export class MediaResource {
+ constructor(private readonly client: OpenWAClient) {}
+
+ /**
+ * Whether conversion is switched on for this deployment AND the ffmpeg binary can
+ * be run. Worth checking once: a caller on a server without it must convert on its
+ * own side rather than receiving an error per request.
+ */
+ conversionStatus(sessionId: string): Promise<MediaConversionAvailability> {
+ return this.client.request<MediaConversionAvailability>({
+ method: 'GET',
+ path: `/api/sessions/${encodeSegment(sessionId)}/media/convert`,
+ });
+ }
+
+ /**
+ * Convert audio into a WhatsApp voice note (Ogg/Opus, mono, tuned for speech).
+ *
+ * WhatsApp shows a playable mic bubble only for this format — sending MP3 bytes with
+ * `ptt: true` produces a voice note that will not play. Pass the returned `base64`
+ * straight to `messages.sendAudio(..., { ptt: true })`. Requires an OPERATOR key.
+ */
+ convertVoice(sessionId: string, input: ConvertMediaInput): Promise<ConvertedMedia> {
+ return this.client.request<ConvertedMedia>({
+ method: 'POST',
+ path: `/api/sessions/${encodeSegment(sessionId)}/media/convert/voice`,
+ body: input,
+ });
+ }
+
+ /**
+ * Convert video into an MP4 every WhatsApp client accepts: baseline H.264 with AAC
+ * audio, long edge bounded at 1280, index moved to the front for immediate playback.
+ * Requires an OPERATOR key.
+ */
+ convertVideo(sessionId: string, input: ConvertMediaInput): Promise<ConvertedMedia> {
+ return this.client.request<ConvertedMedia>({
+ method: 'POST',
+ path: `/api/sessions/${encodeSegment(sessionId)}/media/convert/video`,
+ body: input,
+ });
+ }
+}
diff --git a/sdk/javascript/src/types.ts b/sdk/javascript/src/types.ts
index f31138186..bc84dda1b 100644
--- a/sdk/javascript/src/types.ts
+++ b/sdk/javascript/src/types.ts
@@ -1043,3 +1043,26 @@ export interface SearchResults {
/** Which provider answered (id), e.g. `builtin-fts`. */
provider: string;
}
+
+/** Media to convert: exactly one of `url` or `base64`; `base64` wins if both are given. */
+export interface ConvertMediaInput {
+ /** Public http(s) URL the server fetches (SSRF-guarded). */
+ url?: string;
+ /** Inline bytes. No mimetype is needed — the input format is read from the bytes. */
+ base64?: string;
+}
+
+/** The converted media, in the shape a send endpoint accepts. */
+export interface ConvertedMedia {
+ /** Converted bytes, ready to pass as a send endpoint's `base64`. */
+ base64: string;
+ /** What the bytes now are — not what they were. */
+ mimetype: string;
+ /** Decoded size, so a size check needs no decoding. */
+ bytes: number;
+}
+
+/** Whether server-side conversion can actually be used on this deployment. */
+export interface MediaConversionAvailability {
+ available: boolean;
+}
diff --git a/sdk/javascript/test/resources.test.ts b/sdk/javascript/test/resources.test.ts
index b55754849..ab4aea63e 100644
--- a/sdk/javascript/test/resources.test.ts
+++ b/sdk/javascript/test/resources.test.ts
@@ -116,6 +116,34 @@ describe('CallsResource — exact paths', () => {
});
});
+describe('MediaResource — exact paths', () => {
+ it('conversionStatus GETs the convert root', async () => {
+ const t = new MockTransport().on('GET', /\/media\/convert$/, { body: { available: true } });
+ const res = await client(t).media.conversionStatus('s');
+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s/media/convert');
+ expect(res.available).toBe(true);
+ });
+
+ it('convertVoice POSTs the media to /convert/voice and returns the converted bytes', async () => {
+ const t = new MockTransport().on('POST', /\/media\/convert\/voice$/, {
+ body: { base64: 'T2dnUw==', mimetype: 'audio/ogg; codecs=opus', bytes: 8 },
+ });
+ const res = await client(t).media.convertVoice('s', { base64: 'SUQz' });
+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s/media/convert/voice');
+ expect(t.lastCall!.body).toEqual({ base64: 'SUQz' });
+ expect(res.mimetype).toBe('audio/ogg; codecs=opus');
+ });
+
+ it('convertVideo forwards a url variant verbatim', async () => {
+ const t = new MockTransport().on('POST', /\/media\/convert\/video$/, {
+ body: { base64: 'AAAA', mimetype: 'video/mp4', bytes: 4 },
+ });
+ await client(t).media.convertVideo('s', { url: 'https://example.com/clip.mov' });
+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s/media/convert/video');
+ expect(t.lastCall!.body).toEqual({ url: 'https://example.com/clip.mov' });
+ });
+});
+
describe('ContactsResource — exact paths', () => {
it('list / get / check / profilePicture / phone', async () => {
const t = new MockTransport()
diff --git a/sdk/php/src/Client.php b/sdk/php/src/Client.php
index 981a40e14..a1608b51f 100644
--- a/sdk/php/src/Client.php
+++ b/sdk/php/src/Client.php
@@ -9,6 +9,7 @@ use OpenWA\Exceptions\OpenWAException;
use OpenWA\Http\HttpExecutor;
use OpenWA\Resources\CatalogResource;
use OpenWA\Resources\CallsResource;
+use OpenWA\Resources\MediaResource;
use OpenWA\Resources\ChannelsResource;
use OpenWA\Resources\ChatsResource;
use OpenWA\Resources\ContactsResource;
@@ -67,6 +68,7 @@ class Client
public TemplatesResource $templates;
public ProfileResource $profile;
public CallsResource $calls;
+ public MediaResource $media;
/**
* @param array{
@@ -113,6 +115,7 @@ class Client
$this->templates = new TemplatesResource($this->http);
$this->profile = new ProfileResource($this->http);
$this->calls = new CallsResource($this->http);
+ $this->media = new MediaResource($this->http);
}
/**
diff --git a/sdk/php/src/Resources/MediaResource.php b/sdk/php/src/Resources/MediaResource.php
new file mode 100644
index 000000000..72d1ff7be
--- /dev/null
+++ b/sdk/php/src/Resources/MediaResource.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenWA\Resources;
+
+use OpenWA\Http\HttpExecutor;
+
+/**
+ * Media resource — server-side conversion into the formats WhatsApp plays.
+ *
+ * Backed by src/modules/media/media.controller.ts.
+ */
+class MediaResource
+{
+ private HttpExecutor $http;
+
+ public function __construct(HttpExecutor $http)
+ {
+ $this->http = $http;
+ }
+
+ /**
+ * Whether conversion is switched on for this deployment AND the ffmpeg binary
+ * can be run. Worth checking once: against a server without it a caller must
+ * convert on its own side rather than take an error per request.
+ *
+ * @return array<string,mixed>
+ */
+ public function conversionStatus(string $sessionId): array
+ {
+ return $this->http->request('GET', "/api/sessions/{$this->http->encodeSegment($sessionId)}/media/convert");
+ }
+
+ /**
+ * Convert audio into a WhatsApp voice note (Ogg/Opus, mono, tuned for speech).
+ *
+ * WhatsApp shows a playable mic bubble only for this format — MP3 bytes sent
+ * with ptt produce a voice note that will not play. Pass the returned base64 to
+ * sendAudio with ptt set. Requires an OPERATOR-level key.
+ *
+ * @param array<string,mixed> $media Exactly one of url or base64.
+ * @return array<string,mixed>
+ */
+ public function convertVoice(string $sessionId, array $media): array
+ {
+ return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/media/convert/voice", [], $media);
+ }
+
+ /**
+ * Convert video into an MP4 every WhatsApp client accepts: baseline H.264 with
+ * AAC audio, long edge bounded at 1280, index moved to the front for immediate
+ * playback. Requires an OPERATOR-level key.
+ *
+ * @param array<string,mixed> $media Exactly one of url or base64.
+ * @return array<string,mixed>
+ */
+ public function convertVideo(string $sessionId, array $media): array
+ {
+ return $this->http->request('POST', "/api/sessions/{$this->http->encodeSegment($sessionId)}/media/convert/video", [], $media);
+ }
+}
diff --git a/sdk/php/tests/MediaTest.php b/sdk/php/tests/MediaTest.php
new file mode 100644
index 000000000..3b90c3816
--- /dev/null
+++ b/sdk/php/tests/MediaTest.php
@@ -0,0 +1,40 @@
+<?php
+
+declare(strict_types=1);
+
+namespace OpenWA\Tests;
+
+use PHPUnit\Framework\TestCase;
+
+class MediaTest extends TestCase
+{
+ public function testConversionStatus(): void
+ {
+ $backend = new MockBackend();
+ $backend->on(200, ['available' => true]);
+ $res = $backend->makeClient()->media->conversionStatus('s');
+ $this->assertSame('GET', $backend->calls()[0]['method']);
+ $this->assertSame('/api/sessions/s/media/convert', $backend->calls()[0]['path']);
+ $this->assertTrue($res['available']);
+ }
+
+ public function testConvertVoiceSendsOnlyTheGivenField(): void
+ {
+ $backend = new MockBackend();
+ $backend->on(200, ['base64' => 'T2dnUw==', 'mimetype' => 'audio/ogg; codecs=opus', 'bytes' => 8]);
+ $res = $backend->makeClient()->media->convertVoice('s', ['base64' => 'SUQz']);
+ $this->assertSame('POST', $backend->calls()[0]['method']);
+ $this->assertSame('/api/sessions/s/media/convert/voice', $backend->calls()[0]['path']);
+ $this->assertSame(['base64' => 'SUQz'], $backend->calls()[0]['body']);
+ $this->assertSame('audio/ogg; codecs=opus', $res['mimetype']);
+ }
+
+ public function testConvertVideoWithUrl(): void
+ {
+ $backend = new MockBackend();
+ $backend->on(200, ['base64' => 'AAAA', 'mimetype' => 'video/mp4', 'bytes' => 4]);
+ $backend->makeClient()->media->convertVideo('s', ['url' => 'https://example.com/c.mov']);
+ $this->assertSame('/api/sessions/s/media/convert/video', $backend->calls()[0]['path']);
+ $this->assertSame(['url' => 'https://example.com/c.mov'], $backend->calls()[0]['body']);
+ }
+}
diff --git a/sdk/python/openwa/client.py b/sdk/python/openwa/client.py
index f76b41bc2..b1e3083c5 100644
--- a/sdk/python/openwa/client.py
+++ b/sdk/python/openwa/client.py
@@ -33,6 +33,7 @@ import httpx
from ._http import HttpExecutor, HttpMethod
from .resources import (
CallsResource,
+ MediaResource,
CatalogResource,
ChannelsResource,
ChatsResource,
@@ -159,6 +160,10 @@ class OpenWAClient:
def calls(self) -> CallsResource:
return CallsResource(self._http)
+ @property
+ def media(self) -> MediaResource:
+ return MediaResource(self._http)
+
# ── Auth ─────────────────────────────────────────────────────────
def auth(self) -> AuthValidateResponse:
diff --git a/sdk/python/openwa/resources/__init__.py b/sdk/python/openwa/resources/__init__.py
index dd18533dc..590112e19 100644
--- a/sdk/python/openwa/resources/__init__.py
+++ b/sdk/python/openwa/resources/__init__.py
@@ -14,6 +14,7 @@ from .contacts import ContactsResource
from .groups import GroupsResource
from .health import HealthResource
from .labels import LabelsResource
+from .media import MediaResource
from .messages import MessagesResource
from .profile import ProfileResource
from .search import SearchResource
@@ -31,6 +32,7 @@ __all__ = [
"GroupsResource",
"HealthResource",
"LabelsResource",
+ "MediaResource",
"MessagesResource",
"ProfileResource",
"SearchResource",
diff --git a/sdk/python/openwa/resources/media.py b/sdk/python/openwa/resources/media.py
new file mode 100644
index 000000000..40b16e84f
--- /dev/null
+++ b/sdk/python/openwa/resources/media.py
@@ -0,0 +1,66 @@
+"""Media resource — server-side conversion into the formats WhatsApp plays.
+
+Backed by ``src/modules/media/media.controller.ts``.
+"""
+
+from __future__ import annotations
+
+from typing import TYPE_CHECKING, Optional
+
+from .._http import quote_segment
+from ..types import ConvertedMedia, MediaConversionAvailability
+
+if TYPE_CHECKING:
+ from .._http import HttpExecutor
+
+
+class MediaResource:
+ def __init__(self, http: "HttpExecutor") -> None:
+ self._http = http
+
+ def conversion_status(self, session_id: str) -> MediaConversionAvailability:
+ """Report whether conversion is switched on here AND the ffmpeg binary can be run.
+
+ Worth checking once: against a server without it, a caller must convert on its own
+ side rather than take an error per request.
+ """
+ return self._http.request("GET", f"/api/sessions/{quote_segment(session_id)}/media/convert")
+
+ def convert_voice(
+ self, session_id: str, *, url: Optional[str] = None, base64: Optional[str] = None
+ ) -> ConvertedMedia:
+ """Convert audio into a WhatsApp voice note (Ogg/Opus, mono, tuned for speech).
+
+ WhatsApp shows a playable mic bubble only for this format — MP3 bytes sent with
+ ``ptt=True`` produce a voice note that will not play. Pass the returned ``base64``
+ to ``send_audio(..., ptt=True)``. Requires an OPERATOR-level key.
+ """
+ return self._http.request(
+ "POST",
+ f"/api/sessions/{quote_segment(session_id)}/media/convert/voice",
+ body=_conversion_body(url, base64),
+ )
+
+ def convert_video(
+ self, session_id: str, *, url: Optional[str] = None, base64: Optional[str] = None
+ ) -> ConvertedMedia:
+ """Convert video into an MP4 every WhatsApp client accepts.
+
+ Baseline H.264 with AAC audio, long edge bounded at 1280, index moved to the front
+ for immediate playback. Requires an OPERATOR-level key.
+ """
+ return self._http.request(
+ "POST",
+ f"/api/sessions/{quote_segment(session_id)}/media/convert/video",
+ body=_conversion_body(url, base64),
+ )
+
+
+def _conversion_body(url: Optional[str], base64: Optional[str]) -> dict:
+ """Send only the field that was given: a blank one reads as supplied-but-empty."""
+ body = {}
+ if url is not None:
+ body["url"] = url
+ if base64 is not None:
+ body["base64"] = base64
+ return body
diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.py
index 81db22b79..2299a5b86 100644
--- a/sdk/python/openwa/types.py
+++ b/sdk/python/openwa/types.py
@@ -1053,3 +1053,20 @@ class SearchResults(TypedDict):
total: int
tookMs: int
provider: str
+
+
+class ConvertedMedia(TypedDict, total=False):
+ """Converted media, shaped for handing straight to a send call."""
+
+ #: The converted bytes, ready to use as a send call's ``base64``.
+ base64: str
+ #: What the bytes now are — not what they were.
+ mimetype: str
+ #: Decoded size, so a size check needs no decoding.
+ bytes: int
+
+
+class MediaConversionAvailability(TypedDict, total=False):
+ """Whether server-side conversion can be used on this deployment."""
+
+ available: bool
diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.py
index 23c4a560e..1d2e4f595 100644
--- a/sdk/python/tests/test_sdk.py
+++ b/sdk/python/tests/test_sdk.py
@@ -395,6 +395,33 @@ class TestProfile:
assert backend.calls[-1].body == {"base64": "aGVsbG8=", "mimetype": "image/jpeg"}
+class TestMedia:
+ def test_conversion_status(self):
+ backend = MockBackend().on("GET", "/media/convert", body={"available": True})
+ res = make_client(backend).media.conversion_status("s")
+ assert backend.last_call.url == "http://localhost:2785/api/sessions/s/media/convert"
+ assert res["available"] is True
+
+ def test_convert_voice(self):
+ backend = MockBackend().on(
+ "POST", "/media/convert/voice", body={"base64": "T2dnUw==", "mimetype": "audio/ogg; codecs=opus", "bytes": 8}
+ )
+ res = make_client(backend).media.convert_voice("s", base64="SUQz")
+ assert backend.last_call.method == "POST"
+ assert backend.last_call.url == "http://localhost:2785/api/sessions/s/media/convert/voice"
+ # Only the field that was given: a blank one reads as supplied-but-empty.
+ assert backend.last_call.body == {"base64": "SUQz"}
+ assert res["mimetype"] == "audio/ogg; codecs=opus"
+
+ def test_convert_video_with_url(self):
+ backend = MockBackend().on(
+ "POST", "/media/convert/video", body={"base64": "AAAA", "mimetype": "video/mp4", "bytes": 4}
+ )
+ make_client(backend).media.convert_video("s", url="https://example.com/c.mov")
+ assert backend.last_call.url == "http://localhost:2785/api/sessions/s/media/convert/video"
+ assert backend.last_call.body == {"url": "https://example.com/c.mov"}
+
+
class TestCalls:
def test_reject_call(self):
backend = MockBackend().on("POST", "/reject", body={"success": True})