Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk): declare media mentions in Go/Python/Java and gate numeric enums

Yudhi Armyndharisaaeb5bb5af14
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2084641a4..85781d04e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
+- The Go, Python and Java clients' media/audio sends declare `mentions` (only the JS client could type-safely mention on media), and the contract-shape gate compares numeric enum unions for real (member-level, both sides sorted numerically) instead of skipping them.
- All five SDKs expose `deleteProfilePicture` (the contract's `DELETE /profile/picture` shipped in none of them), and the SDK coverage gate now checks verbs on multi-verb paths, not just path reachability.
- The typed SDKs' message-list records declare `chatName`, `author`, `mediaPath` and `mediaMimetype` (the wire carried all four; every typed client missed them), and the contract-shape gate now maps `MessageRecord` in all four SDKs, including the Python functional-TypedDict form.
- The dashboard's manual WebSocket retry re-registers the message handler on the fresh socket; the handler effect only re-ran on events changes, so a reconnect left the new socket silent while reporting connected.
diff --git a/scripts/check-contract-shapes.mjs b/scripts/check-contract-shapes.mjs
index 3f9a85c75..63fed0442 100644
--- a/scripts/check-contract-shapes.mjs
+++ b/scripts/check-contract-shapes.mjs
@@ -323,12 +323,25 @@ function countUnbalanced(s) {
const MAX_DEPTH = 4;
+/** Sort enum members the same way on both sides: numerically when every member is numeric, else
+ * lexicographically. The two token builders previously both used default .sort() (lexicographic),
+ * which ordered 10 before 2 - consistent by accident, and unable to recognize unquoted numeric
+ * unions in hand types at all, leaving numeric enums ungated.
+ */
+const sortEnumMembers = members =>
+ members.every(m => /^-?\d+(\.\d+)?$/.test(m))
+ ? members.slice().sort((a, b) => Number(a) - Number(b))
+ : members.slice().sort();
+
export function handToken(text, types, depth = 0) {
const t = text.trim().replace(/;$/, '');
if (t.endsWith('[]')) return `array<${handToken(t.slice(0, -2), types, depth)}>`;
if (/^(string|number|boolean|unknown|any)$/.test(t)) return t;
const literals = [...t.matchAll(/'([^']+)'/g)].map(m => m[1]);
- if (literals.length && literals.length === t.split('|').length) return `enum(${literals.slice().sort().join(',')})`;
+ // Unquoted numeric literals (font enums like 0|1|2|6) count too.
+ const numerics = [...t.matchAll(/(?<![\w.'])(-?\d+(?:\.\d+)?)(?![\w.])/g)].map(m => m[1]);
+ if (literals.length && literals.length === t.split('|').length) return `enum(${sortEnumMembers(literals).join(',')})`;
+ if (numerics.length && numerics.length === t.split('|').length) return `enum(${sortEnumMembers(numerics).join(',')})`;
if (t.includes('|')) {
const parts = t
.split('|')
@@ -365,7 +378,7 @@ function baseSchemaToken(node, schemas, depth = 0) {
const target = schemas[node.$ref.split('/').pop()];
return depth < MAX_DEPTH ? schemaToken(target, schemas, depth + 1) : 'object';
}
- if (node.enum) return `enum(${node.enum.slice().sort().join(',')})`;
+ if (node.enum) return `enum(${sortEnumMembers(node.enum.map(String)).join(',')})`;
if (node.type === 'array') return `array<${schemaToken(node.items, schemas, depth)}>`;
if (node.anyOf || node.oneOf) {
const parts = (node.anyOf ?? node.oneOf).map(n => schemaToken(n, schemas, depth + 1));
diff --git a/sdk/go/routing_test.go b/sdk/go/routing_test.go
index 11c8ce24c..c360a266a 100644
--- a/sdk/go/routing_test.go
+++ b/sdk/go/routing_test.go
@@ -160,6 +160,7 @@ func TestRouting(t *testing.T) {
{"Profile.SetProfileName", func(c *Client) { c.Profile.SetProfileName(ctx, "s1", SetProfileNameRequest{}) }, "PUT", "/api/sessions/s1/profile/name"},
{"Profile.SetProfileStatus", func(c *Client) { c.Profile.SetProfileStatus(ctx, "s1", SetProfileStatusRequest{}) }, "PUT", "/api/sessions/s1/profile/status"},
{"Profile.SetProfilePicture", func(c *Client) { c.Profile.SetProfilePicture(ctx, "s1", SetProfilePictureRequest{}) }, "PUT", "/api/sessions/s1/profile/picture"},
+ {"Profile.DeleteProfilePicture", func(c *Client) { c.Profile.DeleteProfilePicture(ctx, "s1") }, "DELETE", "/api/sessions/s1/profile/picture"},
{"Calls.RejectCall", func(c *Client) { c.Calls.RejectCall(ctx, "s1", "call1") }, "POST", "/api/sessions/s1/calls/call1/reject"},
{"Calls.CreateLink", func(c *Client) { c.Calls.CreateLink(ctx, "s1", CreateCallLinkRequest{}) }, "POST", "/api/sessions/s1/calls/link"},
diff --git a/sdk/go/types_message.go b/sdk/go/types_message.go
index 424b8f144..a58651d57 100644
--- a/sdk/go/types_message.go
+++ b/sdk/go/types_message.go
@@ -45,6 +45,8 @@ type SendMediaRequest struct {
// whatsapp-web.js matches the serialized message id, Baileys the raw key id of a message it has
// already stored. Omitted when empty, so an ordinary send carries no quote key.
QuotedMessageID string `json:"quotedMessageId,omitempty"`
+ // WIDs to @mention; the caption must also contain the @<number> token.
+ Mentions []string `json:"mentions,omitempty"`
}
// SendAudioRequest sends audio. PTT sends as a voice note. Server only accepts
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendMediaRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendMediaRequest.java
index 2134ab8be..5a78c3e18 100644
--- a/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendMediaRequest.java
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendMediaRequest.java
@@ -8,7 +8,9 @@ public record SendMediaRequest(
String mimetype,
String filename,
String caption,
- String quotedMessageId) {
+ String quotedMessageId,
+ /** WIDs to @mention; the caption must also contain the @&lt;number&gt; token. */
+ java.util.List<String> mentions) {
public static Builder builder() {
return new Builder();
@@ -22,6 +24,7 @@ public record SendMediaRequest(
private String filename;
private String caption;
private String quotedMessageId;
+ private java.util.List<String> mentions;
public Builder chatId(String v) {
this.chatId = v;
@@ -67,8 +70,14 @@ public record SendMediaRequest(
return this;
}
+ /** WIDs to @mention; the caption must also contain the @&lt;number&gt; token. */
+ public Builder mentions(java.util.List<String> v) {
+ this.mentions = v;
+ return this;
+ }
+
public SendMediaRequest build() {
- return new SendMediaRequest(chatId, url, base64, mimetype, filename, caption, quotedMessageId);
+ return new SendMediaRequest(chatId, url, base64, mimetype, filename, caption, quotedMessageId, mentions);
}
}
}
diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ProfileResourceTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ProfileResourceTest.java
index cfc1249aa..6c55bb89e 100644
--- a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ProfileResourceTest.java
+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/ProfileResourceTest.java
@@ -2,6 +2,7 @@ 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.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.rmyndharis.openwa.ClientConfig;
@@ -25,6 +26,15 @@ class ProfileResourceTest {
assertTrue(tx.lastRequest().body().contains("New Display Name"));
}
+ @Test
+ void deleteProfilePictureSendsDeleteWithoutBody() {
+ tx.respond(200, "{\"success\":true,\"message\":\"Profile picture removed\"}");
+ client.profile.deleteProfilePicture("s");
+ assertEquals("http://h/api/sessions/s/profile/picture", tx.lastRequest().url());
+ assertEquals(HttpMethod.DELETE, tx.lastRequest().method());
+ assertNull(tx.lastRequest().body());
+ }
+
@Test
void setProfileStatusHitsStatusPath() {
tx.respond(200, "{\"success\":true,\"message\":\"Profile status updated\"}");
diff --git a/sdk/javascript/test/resources.test.ts b/sdk/javascript/test/resources.test.ts
index 1bc080bd4..0a60d28dc 100644
--- a/sdk/javascript/test/resources.test.ts
+++ b/sdk/javascript/test/resources.test.ts
@@ -128,6 +128,13 @@ describe('ProfileResource — exact paths and bodies', () => {
await client(t).profile.setProfilePicture('s', { base64: 'aGVsbG8=', mimetype: 'image/png' });
expect(t.lastCall!.body).toEqual({ base64: 'aGVsbG8=', mimetype: 'image/png' });
});
+ it('deleteProfilePicture sends DELETE to the picture route with no body', async () => {
+ const t = new MockTransport().on('DELETE', /\/profile\/picture$/, { body: { success: true } });
+ await client(t).profile.deleteProfilePicture('s');
+ expect(t.lastCall!.method).toBe('DELETE');
+ expect(t.lastCall!.url).toBe('http://x/api/sessions/s/profile/picture');
+ expect(t.lastCall!.body).toBeUndefined();
+ });
});
describe('CallsResource — exact paths', () => {
diff --git a/sdk/php/tests/ProfileCallsTest.php b/sdk/php/tests/ProfileCallsTest.php
index aaea2a1a1..77db27ee9 100644
--- a/sdk/php/tests/ProfileCallsTest.php
+++ b/sdk/php/tests/ProfileCallsTest.php
@@ -38,6 +38,16 @@ class ProfileCallsTest extends TestCase
$this->assertSame(['base64' => 'aW1hZ2U=', 'mimetype' => 'image/jpeg'], $backend->calls()[1]['body']);
}
+ public function testDeleteProfilePicture(): void
+ {
+ $backend = (new MockBackend())->on(200, ['success' => true, 'message' => 'Profile picture removed']);
+ $backend->makeClient()->profile->deleteProfilePicture('s');
+ $call = $backend->calls()[0];
+ $this->assertSame('DELETE', $call['method']);
+ $this->assertSame('/api/sessions/s/profile/picture', $call['path']);
+ $this->assertNull($call['body'] ?? null);
+ }
+
public function testRejectCall(): void
{
$backend = (new MockBackend())->on(200, ['success' => true]);
diff --git a/sdk/python/openwa/types.py b/sdk/python/openwa/types.py
index 375313c38..cd66ac567 100644
--- a/sdk/python/openwa/types.py
+++ b/sdk/python/openwa/types.py
@@ -327,6 +327,8 @@ class SendMediaRequest(TypedDict, total=False):
# Quote an earlier message, turning this send into a reply. Engine-specific: whatsapp-web.js
# matches the serialized message id, Baileys the raw key id of a message it has already stored.
quotedMessageId: str
+ # WIDs to @mention; the caption must also contain the @<number> token.
+ mentions: list[str]
class SendAudioRequest(SendMediaRequest, total=False):
diff --git a/sdk/python/tests/test_sdk.py b/sdk/python/tests/test_sdk.py
index 5a22fea13..425cb89f4 100644
--- a/sdk/python/tests/test_sdk.py
+++ b/sdk/python/tests/test_sdk.py
@@ -463,6 +463,14 @@ class TestProfile:
client.profile.set_profile_picture("s", {"base64": "aGVsbG8=", "mimetype": "image/jpeg"})
assert backend.calls[-1].body == {"base64": "aGVsbG8=", "mimetype": "image/jpeg"}
+ def test_delete_profile_picture(self):
+ backend = MockBackend().on("DELETE", "/profile/picture", body={"success": True, "message": "Profile picture removed"})
+ client = make_client(backend)
+ client.profile.delete_profile_picture("s")
+ assert backend.calls[-1].method == "DELETE"
+ assert backend.calls[-1].url == "http://localhost:2785/api/sessions/s/profile/picture"
+ assert backend.calls[-1].body is None
+
class TestMedia:
def test_conversion_status(self):