Skip to content

Commit

Permalink
Merge pull request #71 from Bindambc/68-update-the-tests
Browse files Browse the repository at this point in the history
Update tests
  • Loading branch information
Bindambc authored Mar 28, 2023
2 parents ade5e1c + cffdfed commit de98ef2
Show file tree
Hide file tree
Showing 7 changed files with 326 additions and 62 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/whatsapp/api/domain/messages/Header.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
/**
* <p>Header content displayed on top of a message. You cannot set a header if your interactive object is of product type</p>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
/**
* The type Button component.
*/
//TODO: review
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ButtonComponent extends Component<ButtonComponent> {

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);

Expand All @@ -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() //
Expand Down Expand Up @@ -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") //
Expand All @@ -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") //
Expand All @@ -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) //
Expand All @@ -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);
Expand Down
Loading

0 comments on commit de98ef2

Please sign in to comment.