Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

fix(sdk): expose quotedMessageId on the Java send-audio request

Yudhi Armyndharis941102df4663
diff --git a/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendAudioRequest.java b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendAudioRequest.java
index 3d410de07..5a4261944 100644
--- a/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendAudioRequest.java
+++ b/sdk/java/src/main/java/com/rmyndharis/openwa/model/SendAudioRequest.java
@@ -8,7 +8,8 @@ public record SendAudioRequest(
String mimetype,
String filename,
String caption,
- Boolean ptt) {
+ Boolean ptt,
+ String quotedMessageId) {
public static Builder builder() {
return new Builder();
@@ -22,6 +23,7 @@ public record SendAudioRequest(
private String filename;
private String caption;
private Boolean ptt;
+ private String quotedMessageId;
public Builder chatId(String v) { this.chatId = v; return this; }
public Builder url(String v) { this.url = v; return this; }
@@ -31,8 +33,15 @@ public record SendAudioRequest(
public Builder caption(String v) { this.caption = v; return this; }
public Builder ptt(Boolean v) { this.ptt = v; return this; }
+ /**
+ * 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.
+ */
+ public Builder quotedMessageId(String v) { this.quotedMessageId = v; return this; }
+
public SendAudioRequest build() {
- return new SendAudioRequest(chatId, url, base64, mimetype, filename, caption, ptt);
+ return new SendAudioRequest(chatId, url, base64, mimetype, filename, caption, ptt, quotedMessageId);
}
}
}
diff --git a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/MessagesResourceTest.java b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/MessagesResourceTest.java
index 744195ddb..4f461b0c1 100644
--- a/sdk/java/src/test/java/com/rmyndharis/openwa/resources/MessagesResourceTest.java
+++ b/sdk/java/src/test/java/com/rmyndharis/openwa/resources/MessagesResourceTest.java
@@ -186,6 +186,15 @@ class MessagesResourceTest {
"s", SendMediaRequest.builder().chatId("[email protected]").url("http://u").quotedMessageId("q-media").build());
assertTrue(tx.lastRequest().body().contains("q-media"));
+ // Audio takes its own record rather than SendMediaRequest, because `ptt` is accepted on this
+ // route alone — and a Java record cannot inherit, so the field has to be declared twice. That
+ // is precisely how send-audio was left as the one quotable route Java could not quote on
+ // while the other four clients could.
+ tx.respond(200, MSG);
+ client.messages.sendAudio(
+ "s", SendAudioRequest.builder().chatId("[email protected]").url("http://u").quotedMessageId("q-audio").build());
+ assertTrue(tx.lastRequest().body().contains("q-audio"));
+
tx.respond(200, MSG);
client.messages.sendLocation(
"s",
@@ -220,12 +229,21 @@ class MessagesResourceTest {
assertTrue(tx.lastRequest().body().contains("q-poll"));
}
- // Known-negative control: an ordinary send must not carry the key at all.
+ // Known-negative control: an ordinary send must not carry the key at all. The server declares
+ // quotedMessageId @IsNotEmpty, so a client that emitted "" or null would 400 every plain send.
+ // Audio is covered separately from the shared media record: it is the one send with its own
+ // record, it is the one that already drifted out of step, and bodySerializer() picks the
+ // serializer per REQUEST TYPE — so routing SendAudioRequest to the null-emitting Gson would
+ // break only audio, and the sendImage case alone would not notice.
@Test
void ordinarySendOmitsTheQuoteKey() {
tx.respond(200, MSG);
client.messages.sendImage("s", SendMediaRequest.builder().chatId("[email protected]").url("http://u").build());
assertTrue(!tx.lastRequest().body().contains("quotedMessageId"));
+
+ tx.respond(200, MSG);
+ client.messages.sendAudio("s", SendAudioRequest.builder().chatId("[email protected]").url("http://u").build());
+ assertTrue(!tx.lastRequest().body().contains("quotedMessageId"));
}
@Test