diff --git a/src/main/java/com/whatsapp/api/domain/messages/Header.java b/src/main/java/com/whatsapp/api/domain/messages/Header.java
index f887f89ee..e28f6d623 100644
--- a/src/main/java/com/whatsapp/api/domain/messages/Header.java
+++ b/src/main/java/com/whatsapp/api/domain/messages/Header.java
@@ -3,7 +3,7 @@
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.whatsapp.api.domain.messages.type.HeaderType;
-
+//TODO: Header is incomplete
/**
*
Header content displayed on top of a message. You cannot set a header if your interactive object is of product type
*/
diff --git a/src/main/java/com/whatsapp/api/domain/templates/ButtonComponent.java b/src/main/java/com/whatsapp/api/domain/templates/ButtonComponent.java
index e4aeed045..0f118964a 100644
--- a/src/main/java/com/whatsapp/api/domain/templates/ButtonComponent.java
+++ b/src/main/java/com/whatsapp/api/domain/templates/ButtonComponent.java
@@ -9,6 +9,7 @@
/**
* The type Button component.
*/
+//TODO: review
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ButtonComponent extends Component {
diff --git a/src/test/java/com/whatsapp/api/examples/SendInteractiveMessageExample.java b/src/test/java/com/whatsapp/api/examples/SendInteractiveMessageExample.java
index dc47eb8a6..c746e38db 100644
--- a/src/test/java/com/whatsapp/api/examples/SendInteractiveMessageExample.java
+++ b/src/test/java/com/whatsapp/api/examples/SendInteractiveMessageExample.java
@@ -1,5 +1,7 @@
package com.whatsapp.api.examples;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.whatsapp.api.TestConstants;
import com.whatsapp.api.WhatsappApiFactory;
import com.whatsapp.api.domain.messages.Action;
@@ -25,7 +27,7 @@
public class SendInteractiveMessageExample {
- public static void main(String[] args) {
+ public static void main(String[] args) throws JsonProcessingException {
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN);
@@ -46,7 +48,7 @@ private static void multiProductMessage(WhatsappBusinessCloudApi whatsappBusines
.setTo(PHONE_NUMBER_1)//
.buildInteractiveMessage(InteractiveMessage.build() //
.setAction(new Action() //
- .setCatalogId("1") //
+ .setCatalogId("6019053994849450") //
.addSection(new Section() //
.setTitle("Title 1") //
.addProductItem(new Product() //
@@ -74,57 +76,65 @@ private static void multiProductMessage(WhatsappBusinessCloudApi whatsappBusines
System.out.println(messageResponse);
}
- private static void productMessage(WhatsappBusinessCloudApi whatsappBusinessCloudApi) {
+ private static void productMessage(WhatsappBusinessCloudApi whatsappBusinessCloudApi) throws JsonProcessingException {
var message = MessageBuilder.builder()//
.setTo(PHONE_NUMBER_1)//
.buildInteractiveMessage(InteractiveMessage.build() //
.setAction(new Action() //
- .setCatalogId("1") //
- .setProductRetailerId("ID_TEST_ITEM_1")) //
+ .setCatalogId("600136185327014") //
+ .setProductRetailerId("r2d5xse158")) //
.setType(InteractiveMessageType.PRODUCT) //
.setBody(new Body() //
.setText("Body message")) //
);
+ System.out.println(new ObjectMapper().writeValueAsString(message));
+
MessageResponse messageResponse = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
System.out.println(messageResponse);
}
- private static void buttonMessage(WhatsappBusinessCloudApi whatsappBusinessCloudApi) {
+ private static void buttonMessage(WhatsappBusinessCloudApi whatsappBusinessCloudApi) throws JsonProcessingException {
var message = MessageBuilder.builder()//
.setTo(PHONE_NUMBER_1)//
.buildInteractiveMessage(InteractiveMessage.build() //
.setAction(new Action() //
.addButton(new Button() //
- .setType(ButtonType.REPLY)
- .setReply(new Reply() //
- .setId("UNIQUE_BUTTON_ID_1") //
- .setTitle("BUTTON_TITLE_1"))) //
+ .setType(ButtonType.REPLY).setReply(new Reply() //
+ .setId("1278454") //
+ .setTitle("YES"))) //
.addButton(new Button() //
- .setType(ButtonType.REPLY)
- .setReply(new Reply() //
- .setId("UNIQUE_BUTTON_ID_2") //
- .setTitle("BUTTON_TITLE_2")))
- ) //
+ .setType(ButtonType.REPLY).setReply(new Reply() //
+ .setId("1278455") //
+ .setTitle("NO"))) //
+ .addButton(new Button() //
+ .setType(ButtonType.REPLY).setReply(new Reply() //
+ .setId("1278456") //
+ .setTitle("CHANGE")))) //
.setType(InteractiveMessageType.BUTTON) //
- .setBody(new Body() //
- .setText("Body message")) //
- );
+ .setHeader(new Header()//
+ .setType(HeaderType.TEXT)//
+ .setText("Appointment confirmation.")//
+
+ ).setBody(new Body() //
+ .setText("Would you like to confirm your appointment for tomorrow?")) //
+ .setFooter(new Footer().setText("Choose an option:")));
+ System.out.println(new ObjectMapper().writeValueAsString(message));
MessageResponse messageResponse = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
System.out.println(messageResponse);
}
- private static void listMessage(WhatsappBusinessCloudApi whatsappBusinessCloudApi) {
+ private static void listMessage(WhatsappBusinessCloudApi whatsappBusinessCloudApi) throws JsonProcessingException {
var message = MessageBuilder.builder()//
.setTo(PHONE_NUMBER_1)//
.buildInteractiveMessage(InteractiveMessage.build() //
.setAction(new Action() //
- .setButtonText("BUTTON_TEXT") //
+ .setButtonText("choose an option") //
.addSection(new Section() //
- .setTitle("Title 1") //
+ .setTitle("Section 1") //
.addRow(new Row() //
.setId("SECTION_1_ROW_1_ID") //
.setTitle("Title 1") //
@@ -139,7 +149,7 @@ private static void listMessage(WhatsappBusinessCloudApi whatsappBusinessCloudAp
.setDescription("SECTION_1_ROW_3_DESCRIPTION")) //
) //
.addSection(new Section() //
- .setTitle("Title 2") //
+ .setTitle("Section 2") //
.addRow(new Row() //
.setId("SECTION_2_ROW_1_ID") //
.setTitle("Title 1") //
@@ -152,8 +162,7 @@ private static void listMessage(WhatsappBusinessCloudApi whatsappBusinessCloudAp
.setId("SECTION_2_ROW_3_ID") //
.setTitle("Title 3") //
.setDescription("SECTION_2_ROW_3_DESCRIPTION")) //
- )
- ) //
+ )) //
.setType(InteractiveMessageType.LIST) //
.setHeader(new Header() //
.setType(HeaderType.TEXT) //
@@ -163,7 +172,7 @@ private static void listMessage(WhatsappBusinessCloudApi whatsappBusinessCloudAp
.setFooter(new Footer() //
.setText("Footer Text")) //
);
-
+ System.out.println(new ObjectMapper().writeValueAsString(message));
MessageResponse messageResponse = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
System.out.println(messageResponse);
diff --git a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessCloudApiTest.java b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessCloudApiTest.java
index 7e992c76b..1690a31c4 100644
--- a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessCloudApiTest.java
+++ b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessCloudApiTest.java
@@ -2,9 +2,12 @@
import com.whatsapp.api.MockServerUtilsTest;
import com.whatsapp.api.domain.media.FileType;
+import com.whatsapp.api.domain.messages.Action;
import com.whatsapp.api.domain.messages.Address;
import com.whatsapp.api.domain.messages.AudioMessage;
+import com.whatsapp.api.domain.messages.Body;
import com.whatsapp.api.domain.messages.BodyComponent;
+import com.whatsapp.api.domain.messages.Button;
import com.whatsapp.api.domain.messages.ButtonComponent;
import com.whatsapp.api.domain.messages.ButtonPayloadParameter;
import com.whatsapp.api.domain.messages.ButtonTextParameter;
@@ -18,15 +21,21 @@
import com.whatsapp.api.domain.messages.DocumentMessage;
import com.whatsapp.api.domain.messages.DocumentParameter;
import com.whatsapp.api.domain.messages.Email;
+import com.whatsapp.api.domain.messages.Footer;
+import com.whatsapp.api.domain.messages.Header;
import com.whatsapp.api.domain.messages.HeaderComponent;
import com.whatsapp.api.domain.messages.Image;
import com.whatsapp.api.domain.messages.ImageMessage;
import com.whatsapp.api.domain.messages.ImageParameter;
+import com.whatsapp.api.domain.messages.InteractiveMessage;
import com.whatsapp.api.domain.messages.Language;
import com.whatsapp.api.domain.messages.Message.MessageBuilder;
import com.whatsapp.api.domain.messages.Name;
import com.whatsapp.api.domain.messages.Org;
import com.whatsapp.api.domain.messages.Phone;
+import com.whatsapp.api.domain.messages.Reply;
+import com.whatsapp.api.domain.messages.Row;
+import com.whatsapp.api.domain.messages.Section;
import com.whatsapp.api.domain.messages.StickerMessage;
import com.whatsapp.api.domain.messages.TemplateMessage;
import com.whatsapp.api.domain.messages.TextMessage;
@@ -37,8 +46,11 @@
import com.whatsapp.api.domain.messages.VideoParameter;
import com.whatsapp.api.domain.messages.type.AddressType;
import com.whatsapp.api.domain.messages.type.ButtonSubType;
+import com.whatsapp.api.domain.messages.type.ButtonType;
import com.whatsapp.api.domain.messages.type.CalendarType;
import com.whatsapp.api.domain.messages.type.EmailType;
+import com.whatsapp.api.domain.messages.type.HeaderType;
+import com.whatsapp.api.domain.messages.type.InteractiveMessageType;
import com.whatsapp.api.domain.messages.type.PhoneType;
import com.whatsapp.api.domain.messages.type.UrlType;
import com.whatsapp.api.domain.templates.type.LanguageType;
@@ -142,7 +154,7 @@ void testSendTextMessage() throws IOException, URISyntaxException, InterruptedEx
}
@Test
- void testContactMessage() throws IOException, URISyntaxException, InterruptedException, JSONException {
+ void testSendContactMessage() throws IOException, URISyntaxException, InterruptedException, JSONException {
mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE));
var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage10.json");
@@ -194,7 +206,7 @@ void testContactMessage() throws IOException, URISyntaxException, InterruptedExc
}
@Test
- void testContactMessage2() throws IOException, URISyntaxException, InterruptedException, JSONException {
+ void testSendContactMessage2() throws IOException, URISyntaxException, InterruptedException, JSONException {
mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE));
var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage10.json");
@@ -304,7 +316,6 @@ void testSendTemplateButtonMessage() throws IOException, URISyntaxException, Int
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
- // System.out.println(recordedRequest.getBody().readUtf8());
JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
@@ -357,7 +368,6 @@ void testSendTemplateButtonMessageWithDateTimeParam() throws IOException, URISyn
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
- //System.out.println(recordedRequest.getBody().readUtf8());
JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
@@ -409,7 +419,6 @@ void testSendTemplateButtonMessageMarketing() throws IOException, URISyntaxExcep
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
- //System.out.println(recordedRequest.getBody().readUtf8());
JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
@@ -447,7 +456,6 @@ void testSendTemplateDocumentPdfMessage() throws IOException, URISyntaxException
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
- //System.out.println(recordedRequest.getBody().readUtf8());
JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
@@ -481,7 +489,6 @@ void testSendTemplateVideoMessage() throws IOException, URISyntaxException, Inte
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
- //System.out.println(recordedRequest.getBody().readUtf8());
JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
@@ -514,7 +521,6 @@ void testSendTemplateAuthMessage() throws IOException, URISyntaxException, Inter
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
- //System.out.println(recordedRequest.getBody().readUtf8());
JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
@@ -539,8 +545,6 @@ void testSendAudioMessage() throws IOException, URISyntaxException, InterruptedE
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
- //System.out.println(recordedRequest.getBody().readUtf8());
-
JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
Assertions.assertEquals("wamid.gBGGSFcCNEOPAgkO_KJ55r4w_ww", response.messages().get(0).id());
@@ -582,7 +586,7 @@ void testSendAudioLinkMessage() throws InterruptedException, JSONException {
}
@Test
- void testSendVideoMessage() throws IOException, URISyntaxException, InterruptedException, JSONException {
+ void testSendVideoMessage() throws InterruptedException, JSONException {
mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE));
var expectedJson = """
@@ -610,16 +614,27 @@ void testSendVideoMessage() throws IOException, URISyntaxException, InterruptedE
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
- // System.out.println(recordedRequest.getBody().readUtf8());
JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
}
@Test
- void testSendImageMessage() throws IOException, URISyntaxException, InterruptedException {
+ void testSendImageMessage() throws InterruptedException, JSONException {
mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE));
+ var expectedJson = """
+ {
+ "messaging_product": "whatsapp",
+ "recipient_type": "individual",
+ "to": "121212121212",
+ "type": "image",
+ "image": {
+ "id": "75457812459735784",
+ "caption": "See the image"
+ }
+ }
+ """;
var message = MessageBuilder.builder()//
.setTo(PHONE_NUMBER_1)//
.buildImageMessage(new ImageMessage()//
@@ -627,45 +642,65 @@ void testSendImageMessage() throws IOException, URISyntaxException, InterruptedE
.setCaption("See the image"));
- var response = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
+ whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
-
- Assertions.assertEquals(String.format("{\"messaging_product\":\"whatsapp\",\"recipient_type\":\"individual\",\"to\":\"%s\",\"type\":\"image\",\"image\":{\"id\":\"75457812459735784\",\"caption\":\"See the image\"}}", PHONE_NUMBER_1), recordedRequest.getBody().readUtf8());
-
- Assertions.assertEquals("wamid.gBGGSFcCNEOPAgkO_KJ55r4w_ww", response.messages().get(0).id());
+ JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
}
@Test
- void testSendDocumentMessage() throws IOException, URISyntaxException, InterruptedException {
+ void testSendDocumentMessage() throws InterruptedException, JSONException {
mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE));
+ var expectedJson = """
+ {
+ "messaging_product": "whatsapp",
+ "recipient_type": "individual",
+ "to": "121212121212",
+ "type": "document",
+ "document": {
+ "id": "78548846588564",
+ "caption": "My document",
+ "filename": "test.pdf"
+ }
+ }
+ """;
var message = MessageBuilder.builder()//
.setTo(PHONE_NUMBER_1)//
.buildDocumentMessage(new DocumentMessage()//
.setId("78548846588564")//
.setFileName("test.pdf").setCaption("My document"));
-
- var response = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
+ whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
+ JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
- Assertions.assertEquals(String.format("{\"messaging_product\":\"whatsapp\",\"recipient_type\":\"individual\",\"to\":\"%s\",\"type\":\"document\",\"document\":{\"id\":\"78548846588564\",\"caption\":\"My document\",\"filename\":\"test.pdf\"}}", PHONE_NUMBER_1), recordedRequest.getBody().readUtf8());
- Assertions.assertEquals("wamid.gBGGSFcCNEOPAgkO_KJ55r4w_ww", response.messages().get(0).id());
}
@Test
- void testSendStickerMessage() throws IOException, URISyntaxException, InterruptedException {
+ void testSendStickerMessage() throws InterruptedException, JSONException {
mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE));
+ var expectedJson = """
+ {
+ "messaging_product": "whatsapp",
+ "recipient_type": "individual",
+ "to": "121212121212",
+ "type": "sticker",
+ "sticker": {
+ "id": "78548846588564"
+ }
+ }
+ """;
+
var message = MessageBuilder.builder()//
.setTo(PHONE_NUMBER_1)//
.buildStickerMessage(new StickerMessage()//
@@ -673,15 +708,119 @@ void testSendStickerMessage() throws IOException, URISyntaxException, Interrupte
var response = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
+ Assertions.assertNotNull(response);
+ RecordedRequest recordedRequest = mockWebServer.takeRequest();
+ Assertions.assertEquals("POST", recordedRequest.getMethod());
+ Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
+
+ JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
+
+ }
+
+ @Test
+ void testSendInteractiveMessageWithButtons() throws InterruptedException, JSONException, IOException, URISyntaxException {
+ mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE));
+
+ var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage11.json");
+
+ var interactive = InteractiveMessage.build() //
+ .setAction(new Action() //
+ .addButton(new Button() //
+ .setType(ButtonType.REPLY).setReply(new Reply() //
+ .setId("1278454") //
+ .setTitle("YES"))) //
+ .addButton(new Button() //
+ .setType(ButtonType.REPLY).setReply(new Reply() //
+ .setId("1278455") //
+ .setTitle("NO"))) //
+ .addButton(new Button() //
+ .setType(ButtonType.REPLY).setReply(new Reply() //
+ .setId("1278456") //
+ .setTitle("CHANGE")))) //
+ .setType(InteractiveMessageType.BUTTON) //
+ .setHeader(new Header()//
+ .setType(HeaderType.TEXT)//
+ .setText("Appointment confirmation.")//
+
+ ).setBody(new Body() //
+ .setText("Would you like to confirm your appointment for tomorrow?")) //
+ .setFooter(new Footer().setText("Choose an option:"));
+
+ var message = MessageBuilder.builder()//
+ .setTo(PHONE_NUMBER_1)//
+ .buildInteractiveMessage(interactive);
+
+ var response = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
+ Assertions.assertNotNull(response);
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
+ //System.out.println(recordedRequest.getBody().readUtf8());
+ JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
+
+ }
+ @Test
+ void testSendInteractiveMessageWithList() throws InterruptedException, JSONException, IOException, URISyntaxException {
+ mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE));
- Assertions.assertEquals(String.format("{\"messaging_product\":\"whatsapp\",\"recipient_type\":\"individual\",\"to\":\"%s\",\"type\":\"sticker\",\"sticker\":{\"id\":\"78548846588564\"}}", PHONE_NUMBER_1), recordedRequest.getBody().readUtf8());
+ var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage12.json");
+
+ var interactive = InteractiveMessage.build() //
+ .setAction(new Action() //
+ .setButtonText("choose an option") //
+ .addSection(new Section() //
+ .setTitle("Section 1") //
+ .addRow(new Row() //
+ .setId("SECTION_1_ROW_1_ID") //
+ .setTitle("Title 1") //
+ .setDescription("SECTION_1_ROW_1_DESCRIPTION")) //
+ .addRow(new Row() //
+ .setId("SECTION_1_ROW_2_ID") //
+ .setTitle("Title 2") //
+ .setDescription("SECTION_1_ROW_2_DESCRIPTION")) //
+ .addRow(new Row() //
+ .setId("SECTION_1_ROW_3_ID") //
+ .setTitle("Title 3") //
+ .setDescription("SECTION_1_ROW_3_DESCRIPTION")) //
+ ) //
+ .addSection(new Section() //
+ .setTitle("Section 2") //
+ .addRow(new Row() //
+ .setId("SECTION_2_ROW_1_ID") //
+ .setTitle("Title 1") //
+ .setDescription("SECTION_2_ROW_1_DESCRIPTION")) //
+ .addRow(new Row() //
+ .setId("SECTION_2_ROW_2_ID") //
+ .setTitle("Title 2") //
+ .setDescription("SECTION_2_ROW_2_DESCRIPTION")) //
+ .addRow(new Row() //
+ .setId("SECTION_2_ROW_3_ID") //
+ .setTitle("Title 3") //
+ .setDescription("SECTION_2_ROW_3_DESCRIPTION")) //
+ )) //
+ .setType(InteractiveMessageType.LIST) //
+ .setHeader(new Header() //
+ .setType(HeaderType.TEXT) //
+ .setText("Header Text")) //
+ .setBody(new Body() //
+ .setText("Body message")) //
+ .setFooter(new Footer() //
+ .setText("Footer Text"));
+
+ var message = MessageBuilder.builder()//
+ .setTo(PHONE_NUMBER_1)//
+ .buildInteractiveMessage(interactive);
+
+ var response = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message);
+ Assertions.assertNotNull(response);
+ RecordedRequest recordedRequest = mockWebServer.takeRequest();
+ Assertions.assertEquals("POST", recordedRequest.getMethod());
+ Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/messages", recordedRequest.getPath());
+
+ JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT);
- Assertions.assertEquals("wamid.gBGGSFcCNEOPAgkO_KJ55r4w_ww", response.messages().get(0).id());
}
@Test
@@ -696,7 +835,7 @@ void testUploadMedia() throws IOException, URISyntaxException, InterruptedExcept
RecordedRequest recordedRequest = mockWebServer.takeRequest();
Assertions.assertEquals("POST", recordedRequest.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/media", recordedRequest.getPath());
-
+ Assertions.assertEquals(103923, recordedRequest.getBodySize());
Assertions.assertEquals("985569392615996", response.id());
}
diff --git a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java
index 6f3f1c872..39d2d2b03 100644
--- a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java
+++ b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java
@@ -189,7 +189,7 @@ void testCreateMessageTemplate3() throws IOException, URISyntaxException, Interr
Assertions.assertNotNull(response);
var request = mockWebServer.takeRequest();
- //System.out.println(request.getBody().readUtf8());
+
Assertions.assertEquals("POST", request.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + WABA_ID + "/message_templates", request.getPath());
@@ -219,7 +219,8 @@ void testCreateMessageTemplate4() throws IOException, URISyntaxException, Interr
.setExample(new Example()//
.addBodyTextExamples("Maria", "04/11/2022", "13:30")//
))//
- .addComponent(new FooterComponent().setText("Utilize um dos botões abaixo para a confirmação")).addComponent(new ButtonComponent()//
+ .addComponent(new FooterComponent().setText("Utilize um dos botões abaixo para a confirmação"))//
+ .addComponent(new ButtonComponent()//
.addButton(new QuickReplyButton("SIM"))//
.addButton(new QuickReplyButton("NÃO"))//
);
@@ -227,7 +228,7 @@ void testCreateMessageTemplate4() throws IOException, URISyntaxException, Interr
whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template);
var request = mockWebServer.takeRequest();
- // System.out.println(request.getBody().readUtf8());
+
Assertions.assertEquals("POST", request.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + WABA_ID + "/message_templates", request.getPath());
@@ -267,7 +268,7 @@ void testCreateMessageTemplateUtility1() throws IOException, URISyntaxException,
whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template);
var request = mockWebServer.takeRequest();
- //System.out.println(request.getBody().readUtf8());
+
Assertions.assertEquals("POST", request.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + WABA_ID + "/message_templates", request.getPath());
@@ -304,7 +305,7 @@ void testCreateMessageTemplateUtility2() throws IOException, URISyntaxException,
whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template);
var request = mockWebServer.takeRequest();
- //System.out.println(request.getBody().readUtf8());
+
Assertions.assertEquals("POST", request.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + WABA_ID + "/message_templates", request.getPath());
@@ -341,7 +342,7 @@ void testCreateMessageTemplateAuthentication() throws IOException, URISyntaxExce
whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template);
var request = mockWebServer.takeRequest();
- // System.out.println(request.getBody().readUtf8());
+
Assertions.assertEquals("POST", request.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + WABA_ID + "/message_templates", request.getPath());
@@ -383,7 +384,7 @@ void testCreateMessageTemplateMarketing2() throws IOException, URISyntaxExceptio
whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template);
var request = mockWebServer.takeRequest();
- //System.out.println(request.getBody().readUtf8());
+
Assertions.assertEquals("POST", request.getMethod());
Assertions.assertEquals("/" + API_VERSION + "/" + WABA_ID + "/message_templates", request.getPath());
@@ -439,14 +440,20 @@ void testDeleteMessageTemplate() throws IOException, URISyntaxException {
}
@Test
- void testRetrieveMessageTemplate1() throws IOException, URISyntaxException {
+ void testRetrieveMessageTemplate1() throws IOException, URISyntaxException, JSONException {
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN);
+ var expectedJson = fromResource("/retTemplate1.json");
+
WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi();
- mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/retTemplate1.json")));
+ mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(expectedJson));
var templates = whatsappBusinessCloudApi.retrieveTemplates(WABA_ID);
+ //TODO: review button
+ //var returnedJson = new ObjectMapper().writeValueAsString(templates);
+ //JSONAssert.assertEquals(expectedJson, returnedJson,JSONCompareMode.STRICT);
+ // data[1].components[3].buttons[0]
Assertions.assertEquals(7, templates.data().size());
Assertions.assertEquals("welcome_template3", templates.data().get(0).name());
diff --git a/src/test/resources/expected/message/expectedMessage11.json b/src/test/resources/expected/message/expectedMessage11.json
new file mode 100644
index 000000000..22b0226b8
--- /dev/null
+++ b/src/test/resources/expected/message/expectedMessage11.json
@@ -0,0 +1,44 @@
+{
+ "messaging_product": "whatsapp",
+ "recipient_type": "individual",
+ "interactive": {
+ "action": {
+ "buttons": [
+ {
+ "type": "reply",
+ "reply": {
+ "id": "1278454",
+ "title": "YES"
+ }
+ },
+ {
+ "type": "reply",
+ "reply": {
+ "id": "1278455",
+ "title": "NO"
+ }
+ },
+ {
+ "type": "reply",
+ "reply": {
+ "id": "1278456",
+ "title": "CHANGE"
+ }
+ }
+ ]
+ },
+ "type": "BUTTON",
+ "header": {
+ "type": "text",
+ "text": "Appointment confirmation."
+ },
+ "body": {
+ "text": "Would you like to confirm your appointment for tomorrow?"
+ },
+ "footer": {
+ "text": "Choose an option:"
+ }
+ },
+ "to": "121212121212",
+ "type": "interactive"
+}
\ No newline at end of file
diff --git a/src/test/resources/expected/message/expectedMessage12.json b/src/test/resources/expected/message/expectedMessage12.json
new file mode 100644
index 000000000..92604b043
--- /dev/null
+++ b/src/test/resources/expected/message/expectedMessage12.json
@@ -0,0 +1,64 @@
+{
+ "messaging_product": "whatsapp",
+ "recipient_type": "individual",
+ "interactive": {
+ "action": {
+ "button": "choose an option",
+ "sections": [
+ {
+ "title": "Section 1",
+ "rows": [
+ {
+ "id": "SECTION_1_ROW_1_ID",
+ "title": "Title 1",
+ "description": "SECTION_1_ROW_1_DESCRIPTION"
+ },
+ {
+ "id": "SECTION_1_ROW_2_ID",
+ "title": "Title 2",
+ "description": "SECTION_1_ROW_2_DESCRIPTION"
+ },
+ {
+ "id": "SECTION_1_ROW_3_ID",
+ "title": "Title 3",
+ "description": "SECTION_1_ROW_3_DESCRIPTION"
+ }
+ ]
+ },
+ {
+ "title": "Section 2",
+ "rows": [
+ {
+ "id": "SECTION_2_ROW_1_ID",
+ "title": "Title 1",
+ "description": "SECTION_2_ROW_1_DESCRIPTION"
+ },
+ {
+ "id": "SECTION_2_ROW_2_ID",
+ "title": "Title 2",
+ "description": "SECTION_2_ROW_2_DESCRIPTION"
+ },
+ {
+ "id": "SECTION_2_ROW_3_ID",
+ "title": "Title 3",
+ "description": "SECTION_2_ROW_3_DESCRIPTION"
+ }
+ ]
+ }
+ ]
+ },
+ "type": "LIST",
+ "header": {
+ "type": "text",
+ "text": "Header Text"
+ },
+ "body": {
+ "text": "Body message"
+ },
+ "footer": {
+ "text": "Footer Text"
+ }
+ },
+ "to": "121212121212",
+ "type": "interactive"
+}
\ No newline at end of file