diff --git a/pom.xml b/pom.xml index 995f47fb7..0a5e61ecd 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,11 @@ converter-jackson ${com.squareup.retrofit2.version} + + com.squareup.okhttp3 + okhttp + ${com.squareup.okhttp3.version} + org.junit.jupiter @@ -88,12 +93,11 @@ test - com.squareup.okhttp3 - okhttp - ${com.squareup.okhttp3.version} + org.skyscreamer + jsonassert + 1.5.1 + test - - diff --git a/src/main/java/com/whatsapp/api/domain/messages/BodyComponent.java b/src/main/java/com/whatsapp/api/domain/messages/BodyComponent.java new file mode 100644 index 000000000..e4a81f90c --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/BodyComponent.java @@ -0,0 +1,22 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.whatsapp.api.domain.messages.type.ComponentType; + + +/** + * The type Body component, to send template messages + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class BodyComponent extends Component { + + + /** + * Instantiates a new Body component, to send template messages + */ + public BodyComponent() { + super(ComponentType.BODY); + } + + +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/ButtonComponent.java b/src/main/java/com/whatsapp/api/domain/messages/ButtonComponent.java new file mode 100644 index 000000000..8fb4d8e98 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/ButtonComponent.java @@ -0,0 +1,79 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.whatsapp.api.domain.messages.type.ButtonSubType; +import com.whatsapp.api.domain.messages.type.ComponentType; + +/** + * The type Button component. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ButtonComponent extends Component { + @JsonProperty("index") + private int index; + @JsonProperty("sub_type") + private ButtonSubType subType; + + + /** + * Instantiates a new Button component. + */ + public ButtonComponent() { + super(ComponentType.BUTTON); + } + + /** + * Instantiates a new Button component. + * + * @param index the index + * @param subType the sub type + */ + public ButtonComponent(int index, ButtonSubType subType) { + super(ComponentType.BUTTON); + this.index = index; + this.subType = subType; + } + + /** + * Gets index. + * + * @return the index + */ + public int getIndex() { + return index; + } + + /** + * Sets index. Required when type=button. Not used for the other types. Only used for Cloud API. + * Position index of the button. You can have up to 3 buttons using index values of 0 to 2. + * + * @param index the index + * @return the index + */ + public ButtonComponent setIndex(int index) { + this.index = index; + return this; + } + + /** + * Gets sub type. + * + * @return the sub type + */ + public ButtonSubType getSubType() { + return subType; + } + + /** + * Sets sub type. Required when type=button. Not used for the other types. + * Type of button to create. + * + * @param subType the sub type + * @return the sub type + */ + public ButtonComponent setSubType(ButtonSubType subType) { + this.subType = subType; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/ButtonPayloadParameter.java b/src/main/java/com/whatsapp/api/domain/messages/ButtonPayloadParameter.java new file mode 100644 index 000000000..1a637e8b9 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/ButtonPayloadParameter.java @@ -0,0 +1,56 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.whatsapp.api.domain.messages.type.ParameterType; + +/** + * The type Button payload parameter. + * + * @see Api reference + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ButtonPayloadParameter extends Parameter { + @JsonProperty("payload") + private String payload; + + + /** + * Instantiates a new Button payload parameter. + */ + public ButtonPayloadParameter() { + super(ParameterType.PAYLOAD); + } + + /** + * Instantiates a new Button payload parameter. + * + * @param payload the payload - Required for quick_reply buttons. + * Developer-defined payload that is returned when the button is clicked in addition to the display text on the button. + */ + public ButtonPayloadParameter(String payload) { + super(ParameterType.PAYLOAD); + this.payload = payload; + } + + /** + * Gets payload. + * + * @return the payload + */ + public String getPayload() { + return payload; + } + + /** + * Sets payload. Required for quick_reply buttons. + * Developer-defined payload that is returned when the button is clicked in addition to the display text on the button. + * + * @param payload the payload + * @return the payload + */ + public ButtonPayloadParameter setPayload(String payload) { + this.payload = payload; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/ButtonTextParameter.java b/src/main/java/com/whatsapp/api/domain/messages/ButtonTextParameter.java new file mode 100644 index 000000000..fe1345028 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/ButtonTextParameter.java @@ -0,0 +1,55 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.whatsapp.api.domain.messages.type.ParameterType; + +/** + * The type Button text parameter. + * Required for URL buttons. + * Developer-provided suffix that is appended to the predefined prefix URL in the template. + * + * @see Api reference + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class ButtonTextParameter extends Parameter { + @JsonProperty("text") + private String text; + + /** + * Instantiates a new Button text parameter. + */ + public ButtonTextParameter() { + super(ParameterType.TEXT); + } + + /** + * Instantiates a new Button text parameter. + * + * @param text the text. Required for URL buttons. Developer-provided suffix that is appended to the predefined prefix URL in the template. + */ + public ButtonTextParameter(String text) { + super(ParameterType.TEXT); + this.text = text; + } + + /** + * Gets text. + * + * @return the text + */ + public String getText() { + return text; + } + + /** + * Sets text. + * + * @param text the text. Required for URL buttons. Developer-provided suffix that is appended to the predefined prefix URL in the template. + * @return the text + */ + public ButtonTextParameter setText(String text) { + this.text = text; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/Component.java b/src/main/java/com/whatsapp/api/domain/messages/Component.java index b1070e69e..d8bbfe09a 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/Component.java +++ b/src/main/java/com/whatsapp/api/domain/messages/Component.java @@ -1,7 +1,12 @@ package com.whatsapp.api.domain.messages; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; -import com.whatsapp.api.domain.templates.type.ComponentType; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; +import com.whatsapp.api.domain.messages.type.ComponentType; import java.util.ArrayList; import java.util.List; @@ -9,17 +14,26 @@ /** * The type Component. */ + @JsonInclude(JsonInclude.Include.NON_NULL) -public class Component { +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.EXISTING_PROPERTY, property = "type") +@JsonSubTypes({@JsonSubTypes.Type(value = ButtonComponent.class, name = "button"), // + @JsonSubTypes.Type(value = HeaderComponent.class, name = "header"), // + @JsonSubTypes.Type(value = BodyComponent.class, name = "body")})// +public abstract class Component> { + @JsonProperty("type") private final ComponentType type; + @JsonProperty("parameters") private List parameters; + /** * Instantiates a new Component. * * @param type the type */ - public Component(ComponentType type) { + @JsonCreator + protected Component(ComponentType type) { this.type = type; } @@ -48,7 +62,7 @@ public List getParameters() { * @param parameters the parameters * @return the parameters */ - public Component setParameters(List parameters) { + public Component setParameters(List parameters) { this.parameters = parameters; return this; } @@ -59,7 +73,7 @@ public Component setParameters(List parameters) { * @param parameter the parameter * @return the component */ - public Component addParameter(Parameter parameter) { + public Component addParameter(Parameter parameter) { if (this.parameters == null) this.parameters = new ArrayList<>(); this.parameters.add(parameter); diff --git a/src/main/java/com/whatsapp/api/domain/messages/Currency.java b/src/main/java/com/whatsapp/api/domain/messages/Currency.java new file mode 100644 index 000000000..f8b3c2067 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/Currency.java @@ -0,0 +1,96 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The type Currency. + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public class Currency { + @JsonProperty("fallback_value") + private String fallbackValue; + @JsonProperty("code") + private String code; + @JsonProperty("amount_1000") + private long amount1000; + + /** + * Instantiates a new Currency. + */ + public Currency() { + } + + /** + * Instantiates a new Currency. + * + * @param fallbackValue the fallback value + * @param code the code + * @param amount1000 the amount 1000 + */ + public Currency(String fallbackValue, String code, long amount1000) { + this.fallbackValue = fallbackValue; + this.code = code; + this.amount1000 = amount1000; + } + + /** + * Gets fallback value. + * + * @return the fallback value + */ + public String getFallbackValue() { + return fallbackValue; + } + + /** + * Sets fallback value. + * + * @param fallbackValue the fallback value + * @return the fallback value + */ + public Currency setFallbackValue(String fallbackValue) { + this.fallbackValue = fallbackValue; + return this; + } + + /** + * Gets code. + * + * @return the code + */ + public String getCode() { + return code; + } + + /** + * Sets code. + * + * @param code the code + * @return the code + */ + public Currency setCode(String code) { + this.code = code; + return this; + } + + /** + * Gets amount 1000. + * + * @return the amount 1000 + */ + public long getAmount1000() { + return amount1000; + } + + /** + * Sets amount 1000. + * + * @param amount1000 the amount 1000 + * @return the amount 1000 + */ + public Currency setAmount1000(long amount1000) { + this.amount1000 = amount1000; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/CurrencyParameter.java b/src/main/java/com/whatsapp/api/domain/messages/CurrencyParameter.java index 443346582..f3ca4b765 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/CurrencyParameter.java +++ b/src/main/java/com/whatsapp/api/domain/messages/CurrencyParameter.java @@ -1,6 +1,7 @@ package com.whatsapp.api.domain.messages; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.messages.type.ParameterType; /** @@ -8,9 +9,9 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) public class CurrencyParameter extends Parameter { - private String fallbackValue; - private String code; - private long amount1000; + + @JsonProperty("currency") + private Currency currency; /** * Instantiates a new Currency parameter. @@ -20,62 +21,32 @@ public CurrencyParameter() { } /** - * Gets fallback value. - * - * @return the fallback value - */ - public String getFallbackValue() { - return fallbackValue; - } - - /** - * Sets fallback value. - * - * @param fallbackValue the fallback value - * @return the fallback value - */ - public CurrencyParameter setFallbackValue(String fallbackValue) { - this.fallbackValue = fallbackValue; - return this; - } - - /** - * Gets code. - * - * @return the code - */ - public String getCode() { - return code; - } - - /** - * Sets code. + * Instantiates a new Currency parameter. * - * @param code the code - * @return the code + * @param currency the currency */ - public CurrencyParameter setCode(String code) { - this.code = code; - return this; + public CurrencyParameter(Currency currency) { + super(ParameterType.CURRENCY); + this.currency = currency; } /** - * Gets amount 1000. + * Gets currency. * - * @return the amount 1000 + * @return the currency */ - public long getAmount1000() { - return amount1000; + public Currency getCurrency() { + return currency; } /** - * Sets amount 1000. + * Sets currency. * - * @param amount1000 the amount 1000 - * @return the amount 1000 + * @param currency the currency + * @return the currency */ - public CurrencyParameter setAmount1000(long amount1000) { - this.amount1000 = amount1000; + public CurrencyParameter setCurrency(Currency currency) { + this.currency = currency; return this; } } diff --git a/src/main/java/com/whatsapp/api/domain/messages/DateTime.java b/src/main/java/com/whatsapp/api/domain/messages/DateTime.java new file mode 100644 index 000000000..25a03a853 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/DateTime.java @@ -0,0 +1,191 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.whatsapp.api.domain.messages.type.CalendarType; + +/** + * The type Date time. + */ +@JsonInclude(Include.NON_NULL) +public class DateTime { + + @JsonProperty("fallback_value") + private String fallbackValue; + @JsonProperty("calendar") + private CalendarType calendar; + @JsonProperty("month") + private Integer month; + @JsonProperty("hour") + private Integer hour; + @JsonProperty("year") + private Integer year; + @JsonProperty("day_of_month") + private Integer dayOfMonth; + @JsonProperty("day_of_week") + private Integer dayOfWeek; + @JsonProperty("minute") + private Integer minute; + + + /** + * Gets fallback value. + * + * @return the fallback value + */ + public String getFallbackValue() { + return fallbackValue; + } + + /** + * Sets fallback value. + * + * @param fallbackValue the fallback value + * @return the fallback value + */ + public DateTime setFallbackValue(String fallbackValue) { + this.fallbackValue = fallbackValue; + return this; + } + + /** + * Gets calendar. + * + * @return the calendar + */ + public CalendarType getCalendar() { + return calendar; + } + + /** + * Sets calendar. + * + * @param calendar the calendar + * @return the calendar + */ + public DateTime setCalendar(CalendarType calendar) { + this.calendar = calendar; + return this; + } + + /** + * Gets month. + * + * @return the month + */ + public Integer getMonth() { + return month; + } + + /** + * Sets month. + * + * @param month the month + * @return the month + */ + public DateTime setMonth(Integer month) { + this.month = month; + return this; + } + + /** + * Gets hour. + * + * @return the hour + */ + public Integer getHour() { + return hour; + } + + /** + * Sets hour. + * + * @param hour the hour + * @return the hour + */ + public DateTime setHour(Integer hour) { + this.hour = hour; + return this; + } + + /** + * Gets year. + * + * @return the year + */ + public Integer getYear() { + return year; + } + + /** + * Sets year. + * + * @param year the year + * @return the year + */ + public DateTime setYear(Integer year) { + this.year = year; + return this; + } + + /** + * Gets day of month. + * + * @return the day of month + */ + public Integer getDayOfMonth() { + return dayOfMonth; + } + + /** + * Sets day of month. + * + * @param dayOfMonth the day of month + * @return the day of month + */ + public DateTime setDayOfMonth(Integer dayOfMonth) { + this.dayOfMonth = dayOfMonth; + return this; + } + + /** + * Gets day of week. + * + * @return the day of week + */ + public Integer getDayOfWeek() { + return dayOfWeek; + } + + /** + * Sets day of week. + * + * @param dayOfWeek the day of week + * @return the day of week + */ + public DateTime setDayOfWeek(Integer dayOfWeek) { + this.dayOfWeek = dayOfWeek; + return this; + } + + /** + * Gets minute. + * + * @return the minute + */ + public Integer getMinute() { + return minute; + } + + /** + * Sets minute. + * + * @param minute the minute + * @return the minute + */ + public DateTime setMinute(Integer minute) { + this.minute = minute; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/DateTimeParameter.java b/src/main/java/com/whatsapp/api/domain/messages/DateTimeParameter.java index 0749057ad..356cef546 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/DateTimeParameter.java +++ b/src/main/java/com/whatsapp/api/domain/messages/DateTimeParameter.java @@ -1,6 +1,7 @@ package com.whatsapp.api.domain.messages; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.messages.type.ParameterType; /** @@ -8,14 +9,10 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) public class DateTimeParameter extends Parameter { - private String fallbackValue; - private String calendar; - private int month; - private int hour; - private int year; - private int dayOfMonth; - private int dayOfWeek; - private int minute; + + @JsonProperty("date_time") + private DateTime dateTime; + /** * Instantiates a new Date time parameter. @@ -24,163 +21,35 @@ public DateTimeParameter() { super(ParameterType.DATE_TIME); } - /** - * Gets fallback value. - * - * @return the fallback value - */ - public String getFallbackValue() { - return fallbackValue; - } - - /** - * Sets fallback value. - * - * @param fallbackValue the fallback value - * @return the fallback value - */ - public DateTimeParameter setFallbackValue(String fallbackValue) { - this.fallbackValue = fallbackValue; - return this; - } - - /** - * Gets calendar. - * - * @return the calendar - */ - public String getCalendar() { - return calendar; - } - - /** - * Sets calendar. - * - * @param calendar the calendar - * @return the calendar - */ - public DateTimeParameter setCalendar(String calendar) { - this.calendar = calendar; - return this; - } - - /** - * Gets month. - * - * @return the month - */ - public int getMonth() { - return month; - } - - /** - * Sets month. - * - * @param month the month - * @return the month - */ - public DateTimeParameter setMonth(int month) { - this.month = month; - return this; - } - - /** - * Gets hour. - * - * @return the hour - */ - public int getHour() { - return hour; - } - - /** - * Sets hour. - * - * @param hour the hour - * @return the hour - */ - public DateTimeParameter setHour(int hour) { - this.hour = hour; - return this; - } - - /** - * Gets year. - * - * @return the year - */ - public int getYear() { - return year; - } - - /** - * Sets year. - * - * @param year the year - * @return the year - */ - public DateTimeParameter setYear(int year) { - this.year = year; - return this; - } /** - * Gets day of month. - * - * @return the day of month - */ - public int getDayOfMonth() { - return dayOfMonth; - } - - /** - * Sets day of month. - * - * @param dayOfMonth the day of month - * @return the day of month - */ - public DateTimeParameter setDayOfMonth(int dayOfMonth) { - this.dayOfMonth = dayOfMonth; - return this; - } - - /** - * Gets day of week. + * Instantiates a new Date time parameter. * - * @return the day of week + * @param dateTime the date time */ - public int getDayOfWeek() { - return dayOfWeek; - } + public DateTimeParameter(DateTime dateTime) { + super(ParameterType.DATE_TIME); - /** - * Sets day of week. - * - * @param dayOfWeek the day of week - * @return the day of week - */ - public DateTimeParameter setDayOfWeek(int dayOfWeek) { - this.dayOfWeek = dayOfWeek; - return this; + this.dateTime = dateTime; } /** - * Gets minute. + * Gets date time. * - * @return the minute + * @return the date time */ - public int getMinute() { - return minute; + public DateTime getDateTime() { + return dateTime; } /** - * Sets minute. + * Sets date time. * - * @param minute the minute - * @return the minute + * @param dateTime the date time + * @return the date time */ - public DateTimeParameter setMinute(int minute) { - this.minute = minute; + public DateTimeParameter setDateTime(DateTime dateTime) { + this.dateTime = dateTime; return this; } } diff --git a/src/main/java/com/whatsapp/api/domain/messages/Document.java b/src/main/java/com/whatsapp/api/domain/messages/Document.java new file mode 100644 index 000000000..72efb301d --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/Document.java @@ -0,0 +1,99 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The type Document. + */ +@JsonInclude(Include.NON_NULL) +public class Document { + + @JsonProperty("id") + private String id; + @JsonProperty("link") + private String link; + + @JsonProperty("filename") + private String fileName; + + /** + * Instantiates a new Document. + * + * @param id the id + * @param link the link + * @param fileName the file name + */ + public Document(String id, String link, String fileName) { + this.id = id; + this.link = link; + this.fileName = fileName; + } + + /** + * Instantiates a new Document. + */ + public Document() { + } + + /** + * Gets id. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + * @return the id + */ + public Document setId(String id) { + this.id = id; + return this; + } + + /** + * Gets link. + * + * @return the link + */ + public String getLink() { + return link; + } + + /** + * Sets link. + * + * @param link the link + * @return the link + */ + public Document setLink(String link) { + this.link = link; + return this; + } + + /** + * Gets file name. + * + * @return the file name + */ + public String getFileName() { + return fileName; + } + + /** + * Sets file name. + * + * @param fileName the file name + * @return the file name + */ + public Document setFileName(String fileName) { + this.fileName = fileName; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/DocumentParameter.java b/src/main/java/com/whatsapp/api/domain/messages/DocumentParameter.java new file mode 100644 index 000000000..e0e89c1ab --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/DocumentParameter.java @@ -0,0 +1,53 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.whatsapp.api.domain.messages.type.ParameterType; + +/** + * The type Document parameter. + */ +@JsonInclude(Include.NON_NULL) +public class DocumentParameter extends Parameter { + + private Document document; + + + /** + * Instantiates a new Document parameter. + */ + public DocumentParameter() { + super(ParameterType.DOCUMENT); + } + + + /** + * Instantiates a new Document parameter. + * + * @param document the document + */ + public DocumentParameter(Document document) { + super(ParameterType.DOCUMENT); + this.document = document; + } + + /** + * Gets document. + * + * @return the document + */ + public Document getDocument() { + return document; + } + + /** + * Sets document. + * + * @param document the document + * @return the document + */ + public DocumentParameter setDocument(Document document) { + this.document = document; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/HeaderComponent.java b/src/main/java/com/whatsapp/api/domain/messages/HeaderComponent.java new file mode 100644 index 000000000..acd3f726f --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/HeaderComponent.java @@ -0,0 +1,17 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.whatsapp.api.domain.messages.type.ComponentType; +@JsonInclude(Include.NON_NULL) + +public class HeaderComponent extends Component { + /** + * Instantiates a new Component. + */ + public HeaderComponent() { + super(ComponentType.HEADER); + } + + +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/Image.java b/src/main/java/com/whatsapp/api/domain/messages/Image.java new file mode 100644 index 000000000..7584ff604 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/Image.java @@ -0,0 +1,75 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The type Image. + */ +@JsonInclude(Include.NON_NULL) +public class Image { + + @JsonProperty("id") + private String id; + + @JsonProperty("link") + private String link; + + /** + * Instantiates a new Image. + */ + public Image() { + } + + /** + * Instantiates a new Image. + * + * @param id the image id + * @param link the image link + */ + public Image(String id, String link) { + this.id = id; + this.link = link; + } + + /** + * Gets id. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + * @return the id + */ + public Image setId(String id) { + this.id = id; + return this; + } + + /** + * Gets link. + * + * @return the link + */ + public String getLink() { + return link; + } + + /** + * Sets link. + * + * @param link the link + * @return the link + */ + public Image setLink(String link) { + this.link = link; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/ImageParameter.java b/src/main/java/com/whatsapp/api/domain/messages/ImageParameter.java new file mode 100644 index 000000000..89f0a8e39 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/ImageParameter.java @@ -0,0 +1,49 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.whatsapp.api.domain.messages.type.ParameterType; + +/** + * The type Image parameter. + */ +public class ImageParameter extends Parameter { + @JsonProperty("image") + private Image image; + + /** + * Instantiates a new Image parameter. + */ + public ImageParameter() { + super(ParameterType.IMAGE); + } + + /** + * Instantiates a new Image parameter. + * + * @param image the image + */ + public ImageParameter(Image image) { + super(ParameterType.IMAGE); + this.image = image; + } + + /** + * Gets image. + * + * @return the image + */ + public Image getImage() { + return image; + } + + /** + * Sets image. + * + * @param image the image + * @return the image + */ + public ImageParameter setImage(Image image) { + this.image = image; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/Parameter.java b/src/main/java/com/whatsapp/api/domain/messages/Parameter.java index 8559aad05..65e90e858 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/Parameter.java +++ b/src/main/java/com/whatsapp/api/domain/messages/Parameter.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.messages.type.ParameterType; /** @@ -9,7 +10,7 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) public class Parameter { - + @JsonProperty("type") private final ParameterType type; /** diff --git a/src/main/java/com/whatsapp/api/domain/messages/TemplateMessage.java b/src/main/java/com/whatsapp/api/domain/messages/TemplateMessage.java index 31163a4a8..69feab8e0 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/TemplateMessage.java +++ b/src/main/java/com/whatsapp/api/domain/messages/TemplateMessage.java @@ -1,6 +1,7 @@ package com.whatsapp.api.domain.messages; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.ArrayList; import java.util.List; @@ -10,8 +11,11 @@ */ @JsonInclude(JsonInclude.Include.NON_NULL) public class TemplateMessage { - private List components; + @JsonProperty("components") + private List> components; + @JsonProperty("name") private String name; + @JsonProperty("language") private Language language; /** @@ -19,7 +23,7 @@ public class TemplateMessage { * * @return the components */ - public List getComponents() { + public List> getComponents() { return components; } @@ -29,7 +33,7 @@ public List getComponents() { * @param components the components * @return the components */ - public TemplateMessage setComponents(List components) { + public TemplateMessage setComponents(List> components) { this.components = components; return this; } @@ -81,7 +85,7 @@ public TemplateMessage setLanguage(Language language) { * @param component the component * @return the template message */ - public TemplateMessage addComponent(Component component) { + public TemplateMessage addComponent(Component component) { if (this.components == null) this.components = new ArrayList<>(); this.components.add(component); diff --git a/src/main/java/com/whatsapp/api/domain/messages/TextParameter.java b/src/main/java/com/whatsapp/api/domain/messages/TextParameter.java index 42e4a1ff8..7ff839383 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/TextParameter.java +++ b/src/main/java/com/whatsapp/api/domain/messages/TextParameter.java @@ -1,14 +1,17 @@ package com.whatsapp.api.domain.messages; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import com.whatsapp.api.domain.messages.type.ParameterType; /** * The type Text parameter. + * Required for URL buttons. + * Developer-provided suffix that is appended to the predefined prefix URL in the template. */ @JsonInclude(JsonInclude.Include.NON_NULL) public class TextParameter extends Parameter { - + @JsonProperty("text") private final String text; diff --git a/src/main/java/com/whatsapp/api/domain/messages/Video.java b/src/main/java/com/whatsapp/api/domain/messages/Video.java new file mode 100644 index 000000000..fa35b83af --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/Video.java @@ -0,0 +1,74 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; + +/** + * The type Video. + */ +@JsonInclude(Include.NON_NULL) +public class Video { + + @JsonProperty("id") + private String id; + @JsonProperty("link") + private String link; + + /** + * Instantiates a new Video. + */ + public Video() { + } + + /** + * Instantiates a new Video. + * + * @param id the id + * @param link the link + */ + public Video(String id, String link) { + this.id = id; + this.link = link; + } + + /** + * Gets id. + * + * @return the id + */ + public String getId() { + return id; + } + + /** + * Sets id. + * + * @param id the id + * @return the id + */ + public Video setId(String id) { + this.id = id; + return this; + } + + /** + * Gets link. + * + * @return the link + */ + public String getLink() { + return link; + } + + /** + * Sets link. + * + * @param link the link + * @return the link + */ + public Video setLink(String link) { + this.link = link; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/VideoParameter.java b/src/main/java/com/whatsapp/api/domain/messages/VideoParameter.java new file mode 100644 index 000000000..a373ac6cd --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/VideoParameter.java @@ -0,0 +1,52 @@ +package com.whatsapp.api.domain.messages; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.whatsapp.api.domain.messages.type.ParameterType; + +/** + * The type Video parameter. + */ +public class VideoParameter extends Parameter { + @JsonProperty("video") + private Video video; + + + /** + * Instantiates a new Parameter. + */ + public VideoParameter() { + super(ParameterType.VIDEO); + } + + + /** + * Instantiates a new Video parameter. + * + * @param type the type + * @param video the video + */ + public VideoParameter(ParameterType type, Video video) { + super(type); + this.video = video; + } + + /** + * Gets video. + * + * @return the video + */ + public Video getVideo() { + return video; + } + + /** + * Sets video. + * + * @param video the video + * @return the video + */ + public VideoParameter setVideo(Video video) { + this.video = video; + return this; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/type/ButtonSubType.java b/src/main/java/com/whatsapp/api/domain/messages/type/ButtonSubType.java new file mode 100644 index 000000000..905a00459 --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/type/ButtonSubType.java @@ -0,0 +1,35 @@ +package com.whatsapp.api.domain.messages.type; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * The enum Button subtype. + * Required when type=button. Not used for the other types. + */ +public enum ButtonSubType { + + /** + * Quick reply button subtype. Refers to a previously created quick reply button that allows for the customer to return a predefined message. + */ + QUICK_REPLY("quick_reply"), + /** + * Url button subtype.Refers to a previously created button that allows the customer to visit the URL generated by appending the text parameter to the predefined prefix URL in the template. + */ + URL("url"); + + private final String value; + + ButtonSubType(String value) { + this.value = value; + } + + /** + * Gets value. + * + * @return the value + */ + @JsonValue + public String getValue() { + return value; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/type/CalendarType.java b/src/main/java/com/whatsapp/api/domain/messages/type/CalendarType.java new file mode 100644 index 000000000..8c757095c --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/type/CalendarType.java @@ -0,0 +1,30 @@ +package com.whatsapp.api.domain.messages.type; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * The enum Calendar type. + */ +public enum CalendarType { + + /** + * Gregorian calendar type. + */ + GREGORIAN("GREGORIAN"); + + private final String value; + + CalendarType(String value) { + this.value = value; + } + + /** + * Gets value. + * + * @return the value + */ + @JsonValue + public String getValue() { + return value; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/type/ComponentType.java b/src/main/java/com/whatsapp/api/domain/messages/type/ComponentType.java new file mode 100644 index 000000000..c75a8baae --- /dev/null +++ b/src/main/java/com/whatsapp/api/domain/messages/type/ComponentType.java @@ -0,0 +1,34 @@ +package com.whatsapp.api.domain.messages.type; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * The enum Component type. + */ +public enum ComponentType { + /** + * Body component type. + */ + BODY("body"), + /** + * Header component type. + */ + HEADER("header"), + + + /** + * Button component type. + */ + BUTTON("button"); + + private final String value; + + ComponentType(String value) { + this.value = value; + } + + @JsonValue + public String getValue() { + return value; + } +} diff --git a/src/main/java/com/whatsapp/api/domain/messages/type/ParameterType.java b/src/main/java/com/whatsapp/api/domain/messages/type/ParameterType.java index 817f82263..1822b0041 100644 --- a/src/main/java/com/whatsapp/api/domain/messages/type/ParameterType.java +++ b/src/main/java/com/whatsapp/api/domain/messages/type/ParameterType.java @@ -17,7 +17,27 @@ public enum ParameterType { /** * Date time parameter type. */ - DATE_TIME("date_time"); + DATE_TIME("date_time"), + /** + * Image parameter type + */ + IMAGE("image"), + + /** + * Video parameter type. + */ + VIDEO("video"), + + /** + * Document parameter type. + */ + DOCUMENT("document"), + + + /** + * Payload parameter type. Indicates the type of parameter for the button. + */ + PAYLOAD("payload"); private final String value; diff --git a/src/main/java/com/whatsapp/api/domain/templates/Button.java b/src/main/java/com/whatsapp/api/domain/templates/Button.java index 59364e644..3ebb7f462 100644 --- a/src/main/java/com/whatsapp/api/domain/templates/Button.java +++ b/src/main/java/com/whatsapp/api/domain/templates/Button.java @@ -3,13 +3,14 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; import com.whatsapp.api.domain.templates.type.ButtonType; /** * The type Button. */ @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME,include = As.EXISTING_PROPERTY, property = "type") @JsonSubTypes({@JsonSubTypes.Type(value = PhoneNumberButton.class, name = "PHONE_NUMBER"),// @JsonSubTypes.Type(value = UrlButton.class, name = "URL"), // @JsonSubTypes.Type(value = QuickReplyButton.class, name = "QUICK_REPLY")}) diff --git a/src/main/java/com/whatsapp/api/domain/templates/Component.java b/src/main/java/com/whatsapp/api/domain/templates/Component.java index b5f92420f..565e6b280 100644 --- a/src/main/java/com/whatsapp/api/domain/templates/Component.java +++ b/src/main/java/com/whatsapp/api/domain/templates/Component.java @@ -1,8 +1,10 @@ package com.whatsapp.api.domain.templates; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonSubTypes; import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeInfo.As; import com.whatsapp.api.domain.templates.type.ComponentType; /** @@ -11,8 +13,11 @@ * @param the type parameter */ @JsonInclude(JsonInclude.Include.NON_NULL) -@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type") -@JsonSubTypes({@JsonSubTypes.Type(value = ButtonComponent.class, name = "BUTTONS"), @JsonSubTypes.Type(value = FooterComponent.class, name = "FOOTER"), @JsonSubTypes.Type(value = HeaderComponent.class, name = "HEADER"), @JsonSubTypes.Type(value = BodyComponent.class, name = "BODY")}) +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = As.EXISTING_PROPERTY, property = "type") +@JsonSubTypes({@JsonSubTypes.Type(value = ButtonComponent.class, name = "BUTTONS"), // + @JsonSubTypes.Type(value = FooterComponent.class, name = "FOOTER"), // + @JsonSubTypes.Type(value = HeaderComponent.class, name = "HEADER"), // + @JsonSubTypes.Type(value = BodyComponent.class, name = "BODY")})// public class Component> { /** * Required. @@ -24,10 +29,11 @@ public class Component> { *
  • BUTTONS
  • * */ + @JsonProperty("type") private ComponentType type; - + @JsonProperty("text") private String text; - + @JsonProperty("example") private Example example; /** diff --git a/src/main/java/com/whatsapp/api/domain/templates/Example.java b/src/main/java/com/whatsapp/api/domain/templates/Example.java index 6aa4899a1..6337e8e2f 100644 --- a/src/main/java/com/whatsapp/api/domain/templates/Example.java +++ b/src/main/java/com/whatsapp/api/domain/templates/Example.java @@ -20,6 +20,8 @@ public class Example { private List headerText; + + /** * Gets header handle. * @@ -86,7 +88,7 @@ public Example setHeaderText(List headerText) { * @param example the example * @return the example */ - public Example addHeaderHandleExample(String... example) { + public Example addHeaderHandleExamples(String... example) { if (this.headerHandle == null) this.headerHandle = new ArrayList<>(); if (example != null) this.headerHandle.addAll(Arrays.stream(example).toList()); return this; @@ -98,7 +100,7 @@ public Example addHeaderHandleExample(String... example) { * @param example the example * @return the example */ - public Example addHeaderTextExample(String... example) { + public Example addHeaderTextExamples(String... example) { if (this.headerText == null) this.headerText = new ArrayList<>(); if (example != null) this.headerText.addAll(Arrays.stream(example).toList()); return this; diff --git a/src/main/java/com/whatsapp/api/domain/templates/PhoneNumberButton.java b/src/main/java/com/whatsapp/api/domain/templates/PhoneNumberButton.java index a760ac40e..4f2aab540 100644 --- a/src/main/java/com/whatsapp/api/domain/templates/PhoneNumberButton.java +++ b/src/main/java/com/whatsapp/api/domain/templates/PhoneNumberButton.java @@ -17,16 +17,17 @@ public class PhoneNumberButton extends Button { * * @param text the text */ - protected PhoneNumberButton(String text) { + public PhoneNumberButton(String text, String phoneNumber) { super(ButtonType.PHONE_NUMBER, text); + this.phoneNumber = phoneNumber; } /** * Instantiates a new Phone number button. */ - protected PhoneNumberButton() { - + public PhoneNumberButton() { + super(ButtonType.PHONE_NUMBER); } /** diff --git a/src/main/java/com/whatsapp/api/exception/WhatsappApiException.java b/src/main/java/com/whatsapp/api/exception/WhatsappApiException.java index 0e2cc1f94..f601507b7 100644 --- a/src/main/java/com/whatsapp/api/exception/WhatsappApiException.java +++ b/src/main/java/com/whatsapp/api/exception/WhatsappApiException.java @@ -40,10 +40,10 @@ public WhatsappApiException(WhatsappApiError whatsappApiError) { public String getMessage() { if (whatsappApiError != null && whatsappApiError.error() != null) { if (whatsappApiError.error().errorData() != null && whatsappApiError.error().errorData().details() != null) - return whatsappApiError.error().message() + " | " + whatsappApiError.error().errorData().details(); + return String.format("[%s] %s | %s", whatsappApiError.error().code(), whatsappApiError.error().message(), whatsappApiError.error().errorData().details()); if (whatsappApiError.error().errorUserMsg() != null) - return whatsappApiError.error().message() + " | " + whatsappApiError.error().errorUserMsg(); + return String.format("[%s] %s | %s", whatsappApiError.error().code(), whatsappApiError.error().message(), whatsappApiError.error().errorUserMsg()); return whatsappApiError.error().message(); } diff --git a/src/test/java/com/whatsapp/api/MockServerUtilsTest.java b/src/test/java/com/whatsapp/api/MockServerUtilsTest.java index 8e3cae4c9..22b7c2523 100644 --- a/src/test/java/com/whatsapp/api/MockServerUtilsTest.java +++ b/src/test/java/com/whatsapp/api/MockServerUtilsTest.java @@ -1,6 +1,8 @@ package com.whatsapp.api; import com.whatsapp.api.configuration.WhatsappApiConfig; +import com.whatsapp.api.impl.WhatsappBusinessCloudApi; +import com.whatsapp.api.impl.WhatsappBusinessManagementApi; import mockwebserver3.MockWebServer; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -11,10 +13,16 @@ @ExtendWith(MockitoExtension.class) public class MockServerUtilsTest extends TestUtils { + public static MockWebServer mockWebServer; public static String baseUrl; + public static WhatsappBusinessCloudApi whatsappBusinessCloudApi; + + public static WhatsappBusinessManagementApi whatsappBusinessManagementApi; + + @BeforeEach public void setUp() throws IOException { @@ -24,6 +32,13 @@ public void setUp() throws IOException { baseUrl = String.format("http://localhost:%s", mockWebServer.getPort()); WhatsappApiConfig.setBaseDomain(baseUrl); + String TOKEN = "df4UIkhjdli48574654SDsdf54654sdf5s4DDF54654654654564654sdfsdf54sdf65s4"; + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + + whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + + whatsappBusinessManagementApi = factory.newBusinessManagementApi(); + } @AfterEach diff --git a/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate1Example.java b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate1Example.java index 4aa019559..ff8566bfa 100644 --- a/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate1Example.java +++ b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate1Example.java @@ -23,7 +23,7 @@ public static void main(String[] args) { var template = new MessageTemplate(); template.setName("welcome_template3")// - .setCategory(Category.TRANSACTIONAL)// + .setCategory(Category.UTILITY)// .setLanguage(LanguageType.EN_US)// .addComponent(new HeaderComponent()// .setText("Wellcome title")// diff --git a/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate4Example.java b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate4Example.java new file mode 100644 index 000000000..b772f9eca --- /dev/null +++ b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate4Example.java @@ -0,0 +1,62 @@ +package com.whatsapp.api.examples; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.whatsapp.api.WhatsappApiFactory; +import com.whatsapp.api.domain.templates.BodyComponent; +import com.whatsapp.api.domain.templates.ButtonComponent; +import com.whatsapp.api.domain.templates.Example; +import com.whatsapp.api.domain.templates.FooterComponent; +import com.whatsapp.api.domain.templates.HeaderComponent; +import com.whatsapp.api.domain.templates.MessageTemplate; +import com.whatsapp.api.domain.templates.QuickReplyButton; +import com.whatsapp.api.domain.templates.type.Category; +import com.whatsapp.api.domain.templates.type.HeaderFormat; +import com.whatsapp.api.domain.templates.type.LanguageType; +import com.whatsapp.api.impl.WhatsappBusinessManagementApi; + +import static com.whatsapp.api.TestConstants.TOKEN; +import static com.whatsapp.api.TestConstants.WABA_ID; + +public class CreateMessageTemplate4Example { + + public static void main(String[] args) throws JsonProcessingException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + + WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + + var template = new MessageTemplate(); + + template.setName("marketing_music_878")// + .setCategory(Category.MARKETING)// + .setLanguage(LanguageType.EN_US)// + .addComponent(new HeaderComponent()// + .setFormat(HeaderFormat.IMAGE) + .setExample(new Example().addHeaderHandleExamples("4::aW1hZ2UvanBlZw==:ARZdpGlLrA9uwIGGZc-UFu5viAD1BkqTCYGL8je2d7xovDZphaWG8gJPTSJfekNchsL3SWdY8-jTA9ZRq_MWro-1wfJnApfbb0ByrUoDb6nNZA:e:1679805732:3449824985304722:100002914375136:ARauotmqlFdTcNENzt0")) + )// + + .addComponent(new BodyComponent()// + .setText("Join us for our live music event on {{1}}. You can get a ticket for only ${{2}}. Thanks.")// + .setExample(new Example()// + .addBodyTextExamples("May 10th, 2023","30")// + ))// + .addComponent(new ButtonComponent()// + + .addButton(new QuickReplyButton("Shop Now") + )// + .addButton(new QuickReplyButton("Stop promotions")// + ) + + + )// + .addComponent(new FooterComponent().setText("Not interested? Tap Stop promotions")) + + + ; + + System.out.println(new ObjectMapper().writeValueAsString(template)); + var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); + + System.out.println(response); + } +} diff --git a/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate5Example.java b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate5Example.java new file mode 100644 index 000000000..8aed565f6 --- /dev/null +++ b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate5Example.java @@ -0,0 +1,65 @@ +package com.whatsapp.api.examples; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.whatsapp.api.WhatsappApiFactory; +import com.whatsapp.api.domain.templates.BodyComponent; +import com.whatsapp.api.domain.templates.ButtonComponent; +import com.whatsapp.api.domain.templates.Example; +import com.whatsapp.api.domain.templates.FooterComponent; +import com.whatsapp.api.domain.templates.HeaderComponent; +import com.whatsapp.api.domain.templates.MessageTemplate; +import com.whatsapp.api.domain.templates.UrlButton; +import com.whatsapp.api.domain.templates.type.Category; +import com.whatsapp.api.domain.templates.type.HeaderFormat; +import com.whatsapp.api.domain.templates.type.LanguageType; +import com.whatsapp.api.impl.WhatsappBusinessManagementApi; + +import java.util.Collections; + +import static com.whatsapp.api.TestConstants.TOKEN; +import static com.whatsapp.api.TestConstants.WABA_ID; + +public class CreateMessageTemplate5Example { + + public static void main(String[] args) throws JsonProcessingException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + + WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + + var template = new MessageTemplate(); + + template.setName("new_classes_pdf_v2")// + .setCategory(Category.UTILITY)// + .setLanguage(LanguageType.PT_BR)// + .addComponent(new HeaderComponent()// + .setFormat(HeaderFormat.DOCUMENT) + .setExample(new Example().addHeaderHandleExamples("4::aW1hZ2UvanBlZw==:ARb0a9E9s7-LdErXAXQCwyh7Oy-_h9gBo4ljPOyyhHynnXo53CK0YUjCCREvS4fB-0CwfSQbNnJve1C9fJC3ikLOfQO-9aeWYdMmkMUJgGJI0g:e:1680011044:3449824985304722:100002914375136:ARZMcC4QfmCW8V85Lco")) + )// + + .addComponent(new BodyComponent()// + .setText("Olá {{1}}, seu professou publicou novas aulas na plataforma de ensino.")// + .setExample(new Example()// + .addBodyTextExamples("Maria")// + ))// + .addComponent(new ButtonComponent()// + + .addButton(new UrlButton("Assistir agora")// + .setUrl("https://www.coursera.org/{{1}}")// + .setUrlExample(Collections.singletonList("https://www.coursera.org/?authMode=login"))// + )// + + + + )// + .addComponent(new FooterComponent().setText("Click on the button below to watch now")) + + + ; + + System.out.println(new ObjectMapper().writeValueAsString(template)); + var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); + + System.out.println(response); + } +} diff --git a/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate6Example.java b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate6Example.java new file mode 100644 index 000000000..b2fb50990 --- /dev/null +++ b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate6Example.java @@ -0,0 +1,62 @@ +package com.whatsapp.api.examples; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.whatsapp.api.WhatsappApiFactory; +import com.whatsapp.api.domain.templates.BodyComponent; +import com.whatsapp.api.domain.templates.ButtonComponent; +import com.whatsapp.api.domain.templates.Example; +import com.whatsapp.api.domain.templates.FooterComponent; +import com.whatsapp.api.domain.templates.HeaderComponent; +import com.whatsapp.api.domain.templates.MessageTemplate; +import com.whatsapp.api.domain.templates.QuickReplyButton; +import com.whatsapp.api.domain.templates.type.Category; +import com.whatsapp.api.domain.templates.type.HeaderFormat; +import com.whatsapp.api.domain.templates.type.LanguageType; +import com.whatsapp.api.impl.WhatsappBusinessManagementApi; + +import static com.whatsapp.api.TestConstants.TOKEN; +import static com.whatsapp.api.TestConstants.WABA_ID; + +public class CreateMessageTemplate6Example { + + public static void main(String[] args) throws JsonProcessingException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + + WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + + var template = new MessageTemplate(); + + template.setName("marketing_coffee")// + .setCategory(Category.MARKETING)// + .setLanguage(LanguageType.PT_BR)// + .addComponent(new HeaderComponent()// + .setFormat(HeaderFormat.IMAGE) + .setExample(new Example().addHeaderHandleExamples("4::aW1hZ2UvanBlZw==:ARZdpGlLrA9uwIGGZc-UFu5viAD1BkqTCYGL8je2d7xovDZphaWG8gJPTSJfekNchsL3SWdY8-jTA9ZRq_MWro-1wfJnApfbb0ByrUoDb6nNZA:e:1679805732:3449824985304722:100002914375136:ARauotmqlFdTcNENzt0")) + )// + + .addComponent(new BodyComponent()// + .setText("Venha aproveitar nossos cafés especiais em nossa super promoção. Nossos expressos são a partir de R${{1}}")// + .setExample(new Example()// + .addBodyTextExamples("15")// + ))// + .addComponent(new ButtonComponent()// + + .addButton(new QuickReplyButton("Saiba mais") + )// + .addButton(new QuickReplyButton("Parar promoções")// + ) + + + )// + .addComponent(new FooterComponent().setText("Sem interesse? Clique em parar promoções")) + + + ; + + System.out.println(new ObjectMapper().writeValueAsString(template)); + var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); + + System.out.println(response); + } +} diff --git a/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate7Example.java b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate7Example.java new file mode 100644 index 000000000..db4ec6867 --- /dev/null +++ b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate7Example.java @@ -0,0 +1,58 @@ +package com.whatsapp.api.examples; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.whatsapp.api.WhatsappApiFactory; +import com.whatsapp.api.domain.templates.BodyComponent; +import com.whatsapp.api.domain.templates.ButtonComponent; +import com.whatsapp.api.domain.templates.Example; +import com.whatsapp.api.domain.templates.FooterComponent; +import com.whatsapp.api.domain.templates.HeaderComponent; +import com.whatsapp.api.domain.templates.MessageTemplate; +import com.whatsapp.api.domain.templates.PhoneNumberButton; +import com.whatsapp.api.domain.templates.type.Category; +import com.whatsapp.api.domain.templates.type.HeaderFormat; +import com.whatsapp.api.domain.templates.type.LanguageType; +import com.whatsapp.api.impl.WhatsappBusinessManagementApi; + +import static com.whatsapp.api.TestConstants.TOKEN; +import static com.whatsapp.api.TestConstants.WABA_ID; + +public class CreateMessageTemplate7Example { + + public static void main(String[] args) throws JsonProcessingException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + + WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + + var template = new MessageTemplate(); + + template.setName("call_to_me")// + .setCategory(Category.UTILITY)// + .setLanguage(LanguageType.PT_BR)// + .addComponent(new HeaderComponent()// + .setText("Problemas com a entrega do seu pedido")// + .setFormat(HeaderFormat.TEXT))// + + .addComponent(new BodyComponent()// + .setText("Olá {{1}}, Tivemos um problema com a entrega do seu pedido {{2}}. Por favor, entre em contato com a central de atendimento para obter mais detalhes")// + + .setExample(new Example()// + .addBodyTextExamples("Maria","FE-15454T45001")))// + .addComponent(new ButtonComponent()// + + .addButton(new PhoneNumberButton("Ligar agora", "16503087300"))// + + + )// + .addComponent(new FooterComponent().setText("Clique no botão abaixo para ligar agora.")) + + + ; + + System.out.println(new ObjectMapper().writeValueAsString(template)); + var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); + + System.out.println(response); + } +} diff --git a/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate8Example.java b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate8Example.java new file mode 100644 index 000000000..4cf37b0c4 --- /dev/null +++ b/src/test/java/com/whatsapp/api/examples/CreateMessageTemplate8Example.java @@ -0,0 +1,46 @@ +package com.whatsapp.api.examples; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.whatsapp.api.WhatsappApiFactory; +import com.whatsapp.api.domain.templates.BodyComponent; +import com.whatsapp.api.domain.templates.Example; +import com.whatsapp.api.domain.templates.FooterComponent; +import com.whatsapp.api.domain.templates.HeaderComponent; +import com.whatsapp.api.domain.templates.MessageTemplate; +import com.whatsapp.api.domain.templates.type.Category; +import com.whatsapp.api.domain.templates.type.HeaderFormat; +import com.whatsapp.api.domain.templates.type.LanguageType; +import com.whatsapp.api.impl.WhatsappBusinessManagementApi; + +import static com.whatsapp.api.TestConstants.TOKEN; +import static com.whatsapp.api.TestConstants.WABA_ID; + +public class CreateMessageTemplate8Example { + + public static void main(String[] args) throws JsonProcessingException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + + WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + + var template = new MessageTemplate(); + + template.setName("auth_app")// + .setCategory(Category.AUTHENTICATION)// + .setLanguage(LanguageType.EN_US)// + .addComponent(new HeaderComponent()// + .setFormat(HeaderFormat.IMAGE).setExample(new Example().addHeaderHandleExamples("4::aW1hZ2UvanBlZw==:ARbzAaeBdkTpPbPQcqoRsHvmI1iJnyxkjZBXVACmVZBGfIOSNOqujojIUCIciq0OttnlTqKZNfbTV81PmOJ2t-eIrJ0MCQFNP5pfMJvAdd-PZQ:e:1680186259:3449824985304722:100002914375136:ARYJQLBIIVIUS1MCM1w")) + )// + .addComponent(new BodyComponent()// + .setText("Hello, scan the QR code or use the code {{1}} to authenticate on the website.")// + .setExample(new Example()// + .addBodyTextExamples("784-H45-7R4")))// + .addComponent(new FooterComponent().setText("Do not share this message with anyone.'"));// + + + System.out.println(new ObjectMapper().writeValueAsString(template)); + var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); + + System.out.println(response); + } +} diff --git a/src/test/java/com/whatsapp/api/examples/SendTemplateAuthMessageExample.java b/src/test/java/com/whatsapp/api/examples/SendTemplateAuthMessageExample.java new file mode 100644 index 000000000..bf8c1fd7a --- /dev/null +++ b/src/test/java/com/whatsapp/api/examples/SendTemplateAuthMessageExample.java @@ -0,0 +1,47 @@ +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.BodyComponent; +import com.whatsapp.api.domain.messages.HeaderComponent; +import com.whatsapp.api.domain.messages.Image; +import com.whatsapp.api.domain.messages.ImageParameter; +import com.whatsapp.api.domain.messages.Language; +import com.whatsapp.api.domain.messages.Message.MessageBuilder; +import com.whatsapp.api.domain.messages.TemplateMessage; +import com.whatsapp.api.domain.messages.TextParameter; +import com.whatsapp.api.domain.templates.type.LanguageType; +import com.whatsapp.api.impl.WhatsappBusinessCloudApi; + +import static com.whatsapp.api.TestConstants.PHONE_NUMBER_1; +import static com.whatsapp.api.TestConstants.PHONE_NUMBER_ID; + +public class SendTemplateAuthMessageExample { + public static void main(String[] args) throws JsonProcessingException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); + + WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(// + new TemplateMessage()// + .setLanguage(new Language(LanguageType.PT_BR))// + .setName("auth_app")// + .addComponent(new HeaderComponent()// + .addParameter(new ImageParameter()// + .setImage(new Image("554066036582230", null)) + ) + + ).addComponent(// + new BodyComponent()// + .addParameter(new TextParameter("T87-G74-876")))// + + ); + System.out.println(new ObjectMapper().writeValueAsString(message)); + + whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message); + } +} diff --git a/src/test/java/com/whatsapp/api/examples/SendTemplateButtonMessage2Example.java b/src/test/java/com/whatsapp/api/examples/SendTemplateButtonMessage2Example.java new file mode 100644 index 000000000..f66969002 --- /dev/null +++ b/src/test/java/com/whatsapp/api/examples/SendTemplateButtonMessage2Example.java @@ -0,0 +1,73 @@ +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.BodyComponent; +import com.whatsapp.api.domain.messages.ButtonComponent; +import com.whatsapp.api.domain.messages.ButtonPayloadParameter; +import com.whatsapp.api.domain.messages.DateTime; +import com.whatsapp.api.domain.messages.DateTimeParameter; +import com.whatsapp.api.domain.messages.Language; +import com.whatsapp.api.domain.messages.Message.MessageBuilder; +import com.whatsapp.api.domain.messages.TemplateMessage; +import com.whatsapp.api.domain.messages.TextParameter; +import com.whatsapp.api.domain.messages.type.ButtonSubType; +import com.whatsapp.api.domain.messages.type.CalendarType; +import com.whatsapp.api.domain.templates.type.LanguageType; +import com.whatsapp.api.impl.WhatsappBusinessCloudApi; + +import static com.whatsapp.api.TestConstants.PHONE_NUMBER_1; +import static com.whatsapp.api.TestConstants.PHONE_NUMBER_ID; + +public class SendTemplateButtonMessage2Example { + public static void main(String[] args) throws JsonProcessingException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); + + WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(// + new TemplateMessage()// + .setLanguage(new Language(LanguageType.PT_BR))// + .setName("schedule_confirmation3")// + .addComponent(new BodyComponent()// + .addParameter(new TextParameter("Mauricio"))// + .addParameter(new DateTimeParameter()// + .setDateTime(new DateTime()// + .setCalendar(CalendarType.GREGORIAN)// + .setDayOfMonth(25)// + .setMonth(3)// + .setYear(2023)// + .setHour(13) + .setMinute(50) + .setDayOfWeek(7) + .setFallbackValue("25/03/2023")// + ))// + .addParameter(new DateTimeParameter()// + .setDateTime(new DateTime()// + .setHour(14)// + .setMinute(30)// + .setFallbackValue("14:34")// + )))// + + .addComponent(new ButtonComponent()// + .setIndex(0)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_YES_48547")))// + .addComponent(new ButtonComponent()// + .setIndex(1)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_NO_48548")))// + .addComponent(new ButtonComponent(2, ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_CH_48549")))// + + + ); + System.out.println(new ObjectMapper().writeValueAsString(message)); + + whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message); + } +} diff --git a/src/test/java/com/whatsapp/api/examples/SendTemplateButtonMessageExample.java b/src/test/java/com/whatsapp/api/examples/SendTemplateButtonMessageExample.java index 8f3efb550..f1141d911 100644 --- a/src/test/java/com/whatsapp/api/examples/SendTemplateButtonMessageExample.java +++ b/src/test/java/com/whatsapp/api/examples/SendTemplateButtonMessageExample.java @@ -2,12 +2,14 @@ import com.whatsapp.api.TestConstants; import com.whatsapp.api.WhatsappApiFactory; -import com.whatsapp.api.domain.messages.Component; +import com.whatsapp.api.domain.messages.BodyComponent; +import com.whatsapp.api.domain.messages.ButtonComponent; +import com.whatsapp.api.domain.messages.ButtonPayloadParameter; import com.whatsapp.api.domain.messages.Language; import com.whatsapp.api.domain.messages.Message.MessageBuilder; import com.whatsapp.api.domain.messages.TemplateMessage; import com.whatsapp.api.domain.messages.TextParameter; -import com.whatsapp.api.domain.templates.type.ComponentType; +import com.whatsapp.api.domain.messages.type.ButtonSubType; import com.whatsapp.api.domain.templates.type.LanguageType; import com.whatsapp.api.impl.WhatsappBusinessCloudApi; @@ -26,11 +28,20 @@ public static void main(String[] args) { new TemplateMessage()// .setLanguage(new Language(LanguageType.PT_BR))// .setName("schedule_confirmation3")// - .addComponent(// - new Component(ComponentType.BODY)// - .addParameter(new TextParameter("Mauricio"))// - .addParameter(new TextParameter("04/11/2022"))// - .addParameter(new TextParameter("14:30")))// + .addComponent(new BodyComponent()// + .addParameter(new TextParameter("Mauricio"))// + .addParameter(new TextParameter("04/11/2022"))// + .addParameter(new TextParameter("14:30")))// + .addComponent(new ButtonComponent()// + .setIndex(0)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_YES_48547")))// + .addComponent(new ButtonComponent()// + .setIndex(1)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_NO_48548")))// + .addComponent(new ButtonComponent(2, ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_CH_48549")))// ); diff --git a/src/test/java/com/whatsapp/api/examples/SendTemplateMarketingMessageExample.java b/src/test/java/com/whatsapp/api/examples/SendTemplateMarketingMessageExample.java new file mode 100644 index 000000000..c269d4796 --- /dev/null +++ b/src/test/java/com/whatsapp/api/examples/SendTemplateMarketingMessageExample.java @@ -0,0 +1,74 @@ +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.BodyComponent; +import com.whatsapp.api.domain.messages.ButtonComponent; +import com.whatsapp.api.domain.messages.ButtonPayloadParameter; +import com.whatsapp.api.domain.messages.Currency; +import com.whatsapp.api.domain.messages.CurrencyParameter; +import com.whatsapp.api.domain.messages.DateTime; +import com.whatsapp.api.domain.messages.DateTimeParameter; +import com.whatsapp.api.domain.messages.HeaderComponent; +import com.whatsapp.api.domain.messages.Image; +import com.whatsapp.api.domain.messages.ImageParameter; +import com.whatsapp.api.domain.messages.Language; +import com.whatsapp.api.domain.messages.Message.MessageBuilder; +import com.whatsapp.api.domain.messages.TemplateMessage; +import com.whatsapp.api.domain.messages.type.ButtonSubType; +import com.whatsapp.api.domain.messages.type.CalendarType; +import com.whatsapp.api.domain.templates.type.LanguageType; +import com.whatsapp.api.impl.WhatsappBusinessCloudApi; + +import static com.whatsapp.api.TestConstants.PHONE_NUMBER_1; +import static com.whatsapp.api.TestConstants.PHONE_NUMBER_ID; + +public class SendTemplateMarketingMessageExample { + public static void main(String[] args) throws JsonProcessingException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); + + WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + + + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(// + new TemplateMessage()// + .setLanguage(new Language(LanguageType.EN_US))// + .setName("marketing_music_2")// + .addComponent(new HeaderComponent()// + .addParameter(new ImageParameter()// + .setImage(new Image()// + .setId("3196424913981611")// + ) + )).addComponent(// + new BodyComponent()// + .addParameter(new DateTimeParameter()// + .setDateTime(new DateTime()// + .setCalendar(CalendarType.GREGORIAN)// + .setDayOfMonth(26)// + .setMonth(3)// + .setYear(2023)// + .setHour(10) + .setMinute(50) + .setDayOfWeek(1).setFallbackValue("May 10th, 2023")// + ))// + .addParameter(new CurrencyParameter()// + .setCurrency(new Currency("$35", "USD", 30000))))// + + .addComponent(new ButtonComponent()// + .setIndex(0)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_SHN_454584")))// + .addComponent(new ButtonComponent()// + .setIndex(1)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_SPR_454585")))// + ); + System.out.println(new ObjectMapper().writeValueAsString(message)); + + whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message); + } +} diff --git a/src/test/java/com/whatsapp/api/examples/SendTemplateTextMessageExample.java b/src/test/java/com/whatsapp/api/examples/SendTemplateTextMessageExample.java index 6b2e1f4ee..901ba7c6f 100644 --- a/src/test/java/com/whatsapp/api/examples/SendTemplateTextMessageExample.java +++ b/src/test/java/com/whatsapp/api/examples/SendTemplateTextMessageExample.java @@ -2,12 +2,11 @@ import com.whatsapp.api.TestConstants; import com.whatsapp.api.WhatsappApiFactory; -import com.whatsapp.api.domain.messages.Component; +import com.whatsapp.api.domain.messages.BodyComponent; import com.whatsapp.api.domain.messages.Language; import com.whatsapp.api.domain.messages.Message.MessageBuilder; import com.whatsapp.api.domain.messages.TemplateMessage; import com.whatsapp.api.domain.messages.TextParameter; -import com.whatsapp.api.domain.templates.type.ComponentType; import com.whatsapp.api.domain.templates.type.LanguageType; import com.whatsapp.api.impl.WhatsappBusinessCloudApi; @@ -25,10 +24,9 @@ public static void main(String[] args) { .buildTemplateMessage(// new TemplateMessage()// .setLanguage(new Language(LanguageType.PT_BR)).setName("number_confirmation")// - .addComponent(// - new Component(ComponentType.BODY)// - .addParameter(new TextParameter("18754269072")// - )) + .addComponent(new BodyComponent()// + .addParameter(new TextParameter("18754269072")// + )) ); diff --git a/src/test/java/com/whatsapp/api/examples/SendTemplateUtilityDocumentMessageExample.java b/src/test/java/com/whatsapp/api/examples/SendTemplateUtilityDocumentMessageExample.java new file mode 100644 index 000000000..af481f8bd --- /dev/null +++ b/src/test/java/com/whatsapp/api/examples/SendTemplateUtilityDocumentMessageExample.java @@ -0,0 +1,54 @@ +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.BodyComponent; +import com.whatsapp.api.domain.messages.ButtonComponent; +import com.whatsapp.api.domain.messages.ButtonTextParameter; +import com.whatsapp.api.domain.messages.Document; +import com.whatsapp.api.domain.messages.DocumentParameter; +import com.whatsapp.api.domain.messages.HeaderComponent; +import com.whatsapp.api.domain.messages.Language; +import com.whatsapp.api.domain.messages.Message.MessageBuilder; +import com.whatsapp.api.domain.messages.TemplateMessage; +import com.whatsapp.api.domain.messages.TextParameter; +import com.whatsapp.api.domain.messages.type.ButtonSubType; +import com.whatsapp.api.domain.templates.type.LanguageType; +import com.whatsapp.api.impl.WhatsappBusinessCloudApi; + +import static com.whatsapp.api.TestConstants.PHONE_NUMBER_1; +import static com.whatsapp.api.TestConstants.PHONE_NUMBER_ID; + +public class SendTemplateUtilityDocumentMessageExample { + public static void main(String[] args) throws JsonProcessingException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); + + WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(// + new TemplateMessage()// + .setLanguage(new Language(LanguageType.EN_US))// + .setName("new_classes_pdf")// + .addComponent(new HeaderComponent()// + .addParameter(new DocumentParameter()// + .setDocument(new Document()// + .setFileName("Class.pdf").setId("928860901494862")// + ))// + ).addComponent(// + new BodyComponent()// + .addParameter(new TextParameter("Mauricio Binda")))// + .addComponent(new ButtonComponent()// + .setIndex(0)// + .setSubType(ButtonSubType.URL)// + .addParameter(new ButtonTextParameter("career-academy/?trk_ref=globalnav")))// + + ); + System.out.println(new ObjectMapper().writeValueAsString(message)); + + whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message); + } +} diff --git a/src/test/java/com/whatsapp/api/exception/WhatsappApiExceptionTest.java b/src/test/java/com/whatsapp/api/exception/WhatsappApiExceptionTest.java index dd0643ee1..5579daace 100644 --- a/src/test/java/com/whatsapp/api/exception/WhatsappApiExceptionTest.java +++ b/src/test/java/com/whatsapp/api/exception/WhatsappApiExceptionTest.java @@ -33,8 +33,8 @@ void testConstructor2() { "An error occurred"))); assertNull(actualWhatsappApiException.getCause()); assertEquals(0, actualWhatsappApiException.getSuppressed().length); - assertEquals("Not all who wander are lost | Details", actualWhatsappApiException.getMessage()); - assertEquals("Not all who wander are lost | Details", actualWhatsappApiException.getLocalizedMessage()); + assertEquals("[1] Not all who wander are lost | Details", actualWhatsappApiException.getMessage()); + assertEquals("[1] Not all who wander are lost | Details", actualWhatsappApiException.getLocalizedMessage()); } /** @@ -62,17 +62,17 @@ void testConstructor3() { @Test void testGetMessage() { assertNull((new WhatsappApiException()).getMessage()); - assertEquals("Not all who wander are lost | Details", + assertEquals("[1] Not all who wander are lost | Details", (new WhatsappApiException( new WhatsappApiError(new Error(1, "Details", -1, "42", "Not all who wander are lost", "Messaging Product", new ErrorData("Messaging Product", "Details", "Blame Field Specs"), "Type", true, "Dr", "An error occurred")))).getMessage()); - assertEquals("Not all who wander are lost | An error occurred", + assertEquals("[1] Not all who wander are lost | An error occurred", (new WhatsappApiException( new WhatsappApiError(new Error(1, "Details", -1, "42", "Not all who wander are lost", "Messaging Product", new ErrorData("Messaging Product", null, "Blame Field Specs"), "Type", true, "Dr", "An error occurred")))).getMessage()); - assertEquals("Not all who wander are lost | An error occurred", + assertEquals("[1] Not all who wander are lost | An error occurred", (new WhatsappApiException(new WhatsappApiError(new Error(1, "Details", -1, "42", "Not all who wander are lost", "Messaging Product", null, "Type", true, "Dr", "An error occurred")))) .getMessage()); diff --git a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessCloudApiTest.java b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessCloudApiTest.java index f48c23681..03799fa6b 100644 --- a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessCloudApiTest.java +++ b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessCloudApiTest.java @@ -1,37 +1,74 @@ package com.whatsapp.api.impl; import com.whatsapp.api.MockServerUtilsTest; -import com.whatsapp.api.TestConstants; -import com.whatsapp.api.WhatsappApiFactory; import com.whatsapp.api.domain.media.FileType; import com.whatsapp.api.domain.messages.AudioMessage; -import com.whatsapp.api.domain.messages.Component; +import com.whatsapp.api.domain.messages.BodyComponent; +import com.whatsapp.api.domain.messages.ButtonComponent; +import com.whatsapp.api.domain.messages.ButtonPayloadParameter; +import com.whatsapp.api.domain.messages.ButtonTextParameter; +import com.whatsapp.api.domain.messages.Currency; +import com.whatsapp.api.domain.messages.CurrencyParameter; +import com.whatsapp.api.domain.messages.DateTime; +import com.whatsapp.api.domain.messages.DateTimeParameter; +import com.whatsapp.api.domain.messages.Document; import com.whatsapp.api.domain.messages.DocumentMessage; +import com.whatsapp.api.domain.messages.DocumentParameter; +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.Language; import com.whatsapp.api.domain.messages.Message.MessageBuilder; import com.whatsapp.api.domain.messages.StickerMessage; import com.whatsapp.api.domain.messages.TemplateMessage; import com.whatsapp.api.domain.messages.TextMessage; import com.whatsapp.api.domain.messages.TextParameter; +import com.whatsapp.api.domain.messages.Video; import com.whatsapp.api.domain.messages.VideoMessage; -import com.whatsapp.api.domain.templates.type.ComponentType; +import com.whatsapp.api.domain.messages.VideoParameter; +import com.whatsapp.api.domain.messages.type.ButtonSubType; +import com.whatsapp.api.domain.messages.type.CalendarType; import com.whatsapp.api.domain.templates.type.LanguageType; import com.whatsapp.api.exception.WhatsappApiException; import com.whatsapp.api.utils.Formatter; import mockwebserver3.MockResponse; import mockwebserver3.RecordedRequest; +import org.json.JSONException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; import java.io.IOException; import java.net.URISyntaxException; -import static com.whatsapp.api.TestConstants.PHONE_NUMBER_1; -import static com.whatsapp.api.TestConstants.PHONE_NUMBER_ID; import static com.whatsapp.api.configuration.WhatsappApiConfig.API_VERSION; public class WhatsappBusinessCloudApiTest extends MockServerUtilsTest { + + private final String PHONE_NUMBER_1 = "121212121212"; + private final String PHONE_NUMBER_ID = "888888888888"; + + private final String EXPECTED_FOLDER = "/expected/message/"; + + private final String DEFAULT_SEND_MESSAGE_RESPONSE = """ + { + "messaging_product": "whatsapp", + "contacts": [ + { + "input": "48XXXXXXXXX", + "wa_id": "48XXXXXXXXX " + } + ], + "messages": [ + { + "id": "wamid.gBGGSFcCNEOPAgkO_KJ55r4w_ww" + } + ] + } + """; + @Test void testSendMessageError() throws InterruptedException { mockWebServer.enqueue(new MockResponse().setResponseCode(500).setBody("{" +// @@ -48,9 +85,7 @@ void testSendMessageError() throws InterruptedException { " }\n" +// "}")); - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); var message = MessageBuilder.builder()// .setTo(PHONE_NUMBER_1)// .buildTextMessage(new TextMessage()// @@ -67,16 +102,15 @@ void testSendMessageError() throws InterruptedException { Assertions.assertEquals(String.format("{\"messaging_product\":\"whatsapp\",\"recipient_type\":\"individual\",\"to\":\"%s\",\"type\":\"text\",\"text\":{\"preview_url\":false,\"body\":\"*Hello world!*\\nSome code here: \\n```hello world code here```\"}}", PHONE_NUMBER_1), recordedRequest.getBody().readUtf8()); - Assertions.assertEquals("(#130429) Rate limit hit | Message failed to send because there were too many messages sent from this phone number in a short period of time", ex.getMessage()); + Assertions.assertEquals("[130429] (#130429) Rate limit hit | Message failed to send because there were too many messages sent from this phone number in a short period of time", ex.getMessage()); } @Test - void testSendTextMessage() throws IOException, URISyntaxException, InterruptedException { - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/message.json"))); + void testSendTextMessage() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); + var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage1.json"); - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); var message = MessageBuilder.builder()// .setTo(PHONE_NUMBER_1)// .buildTextMessage(new TextMessage()// @@ -90,31 +124,63 @@ void testSendTextMessage() throws IOException, URISyntaxException, InterruptedEx 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\":\"text\",\"text\":{\"preview_url\":false,\"body\":\"*Hello world!*\\nSome code here: \\n```hello world code here```\"}}", PHONE_NUMBER_1), recordedRequest.getBody().readUtf8()); - + JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT); Assertions.assertEquals("wamid.gBGGSFcCNEOPAgkO_KJ55r4w_ww", response.messages().get(0).id()); } @Test - void testSendTemplateTextMessage() throws IOException, URISyntaxException, InterruptedException { - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/message.json"))); + void testSendTemplateTextMessage() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); + + var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage2.json"); + + var templateMessage = new TemplateMessage()// + .setLanguage(new Language(LanguageType.PT_BR))// + .setName("number_confirmation")// + .addComponent(new BodyComponent().addParameter(new TextParameter("18754269072"))); + + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(templateMessage); + + 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()); - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); + JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT); - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + } + + @Test + void testSendTemplateButtonMessage() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); + var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage3.json"); var templateMessage = new TemplateMessage()// .setLanguage(new Language(LanguageType.PT_BR))// - .setName("number_confirmation")// - .addComponent(// - new Component(ComponentType.BODY)// - .addParameter(new TextParameter("18754269072")// - )); + .setName("schedule_confirmation3")// + .addComponent(new BodyComponent()// + .addParameter(new TextParameter("Mauricio"))// + .addParameter(new TextParameter("04/11/2022"))// + .addParameter(new TextParameter("14:30")))// + .addComponent(new ButtonComponent()// + .setIndex(0)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_YES_48547")))// + .addComponent(new ButtonComponent()// + .setIndex(1)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_NO_48548")))// + .addComponent(new ButtonComponent(2, ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_CH_48549"))); + var message = MessageBuilder.builder()// - .setTo(TestConstants.PHONE_NUMBER_1)// + .setTo(PHONE_NUMBER_1)// .buildTemplateMessage(templateMessage); whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message); @@ -122,22 +188,229 @@ void testSendTemplateTextMessage() 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); - var expectedBody = """ - {"messaging_product":"whatsapp","recipient_type":"individual","to":"%s","type":"template","template":{"components":[{"type":"BODY","parameters":[{"type":"text","text":"18754269072"}]}],"name":"number_confirmation","language":{"code":"pt_BR"}}}"""; + } + + @Test + void testSendTemplateButtonMessageWithDateTimeParam() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); - Assertions.assertEquals(String.format(expectedBody, PHONE_NUMBER_1), recordedRequest.getBody().readUtf8()); + var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage4.json"); + + var templateMessage = new TemplateMessage()// + .setLanguage(new Language(LanguageType.PT_BR))// + .setName("schedule_confirmation3")// + .addComponent(new BodyComponent()// + .addParameter(new TextParameter("Mauricio"))// + .addParameter(new DateTimeParameter()// + .setDateTime(new DateTime()// + .setCalendar(CalendarType.GREGORIAN)// + .setDayOfMonth(25)// + .setMonth(3)// + .setYear(2023)// + .setHour(13).setMinute(50).setDayOfWeek(7).setFallbackValue("25/03/2023")// + ))// + .addParameter(new DateTimeParameter()// + .setDateTime(new DateTime()// + .setHour(14)// + .setMinute(30)// + .setFallbackValue("14:34")// + )))// + + .addComponent(new ButtonComponent()// + .setIndex(0)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_YES_48547")))// + .addComponent(new ButtonComponent()// + .setIndex(1)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_NO_48548")))// + .addComponent(new ButtonComponent(2, ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_CH_48549"))); + + + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(templateMessage); + + 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()); + //System.out.println(recordedRequest.getBody().readUtf8()); + + JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT); } @Test - void testSendAudioMessage() throws IOException, URISyntaxException, InterruptedException { - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/message.json"))); + void testSendTemplateButtonMessageMarketing() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); + + var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage5.json"); + + var templateMessage = new TemplateMessage()// + .setLanguage(new Language(LanguageType.EN_US))// + .setName("marketing_music_2")// + .addComponent(new HeaderComponent()// + .addParameter(new ImageParameter()// + .setImage(new Image()// + .setId("3196424913981611")// + ))).addComponent(// + new BodyComponent()// + .addParameter(new DateTimeParameter()// + .setDateTime(new DateTime()// + .setCalendar(CalendarType.GREGORIAN)// + .setDayOfMonth(26)// + .setMonth(3)// + .setYear(2023)// + .setHour(10).setMinute(50).setDayOfWeek(1).setFallbackValue("May 10th, 2023")// + ))// + .addParameter(new CurrencyParameter()// + .setCurrency(new Currency("$35", "USD", 30000))))// + + .addComponent(new ButtonComponent()// + .setIndex(0)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_SHN_454584")))// + .addComponent(new ButtonComponent()// + .setIndex(1)// + .setSubType(ButtonSubType.QUICK_REPLY)// + .addParameter(new ButtonPayloadParameter("OP_SPR_454585"))); - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(templateMessage); + + 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()); + //System.out.println(recordedRequest.getBody().readUtf8()); + + JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT); + + } + + @Test + void testSendTemplateDocumentPdfMessage() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); + + var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage6.json"); + + var templateMessage = new TemplateMessage()// + .setLanguage(new Language(LanguageType.EN_US))// + .setName("new_classes_pdf")// + .addComponent(new HeaderComponent()// + .addParameter(new DocumentParameter()// + .setDocument(new Document()// + .setFileName("Class.pdf").setId("928860901494862")// + ))// + ).addComponent(// + new BodyComponent()// + .addParameter(new TextParameter("Mauricio Binda")))// + .addComponent(new ButtonComponent()// + .setIndex(0)// + .setSubType(ButtonSubType.URL)// + .addParameter(new ButtonTextParameter("career-academy/?trk_ref=globalnav"))); + + + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(templateMessage); + + 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()); + //System.out.println(recordedRequest.getBody().readUtf8()); + + JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT); + + } + + @Test + void testSendTemplateVideoMessage() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); + + var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage8.json"); + + var templateMessage = new TemplateMessage()// + .setLanguage(new Language(LanguageType.EN_US))// + .setName("video_tm")// + .addComponent(new HeaderComponent()// + .addParameter(new VideoParameter()// + .setVideo(new Video()// + .setId("4548775454857854")))// + ).addComponent(// + new BodyComponent()// + .addParameter(new TextParameter("Mauricio Binda")))// + ; + + + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(templateMessage); + + 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()); + //System.out.println(recordedRequest.getBody().readUtf8()); + + JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT); + + } + + @Test + void testSendTemplateAuthMessage() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); + + var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage9.json"); + + var templateMessage = new TemplateMessage()// + .setLanguage(new Language(LanguageType.PT_BR))// + .setName("auth_app")// + .addComponent(new HeaderComponent()// + .addParameter(new ImageParameter()// + .setImage(new Image("554066036582230", null))) + + ).addComponent(// + new BodyComponent()// + .addParameter(new TextParameter("T87-G74-876")));// + + + var message = MessageBuilder.builder()// + .setTo(PHONE_NUMBER_1)// + .buildTemplateMessage(templateMessage); + + 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()); + //System.out.println(recordedRequest.getBody().readUtf8()); + + JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT); + + } + + + @Test + void testSendAudioMessage() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); + + var expectedJson = fromResource(EXPECTED_FOLDER + "expectedMessage7.json"); + var message = MessageBuilder.builder()// .setTo(PHONE_NUMBER_1)// .buildAudioMessage(new AudioMessage()// @@ -150,23 +423,33 @@ void testSendAudioMessage() throws IOException, URISyntaxException, InterruptedE 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\":\"audio\",\"audio\":{\"id\":\"4545454545454\"}}", PHONE_NUMBER_1), recordedRequest.getBody().readUtf8()); + //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()); } @Test - void testSendAudioLinkMessage() throws IOException, URISyntaxException, InterruptedException { - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/message.json"))); - - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); + void testSendAudioLinkMessage() 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": "audio", + "audio": { + "link": "https://testeteste778787878.com/audio.mp3" + } + } + """; - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); - var link = "https://testeteste778787878.com/audio.mp3"; var message = MessageBuilder.builder()// .setTo(PHONE_NUMBER_1)// .buildAudioMessage(new AudioMessage()// - .setLink(link)); + .setLink("https://testeteste778787878.com/audio.mp3")); var response = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message); @@ -174,19 +457,30 @@ void testSendAudioLinkMessage() throws IOException, URISyntaxException, Interrup 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\":\"audio\",\"audio\":{\"link\":\"%s\"}}", PHONE_NUMBER_1, link), recordedRequest.getBody().readUtf8()); Assertions.assertEquals("wamid.gBGGSFcCNEOPAgkO_KJ55r4w_ww", response.messages().get(0).id()); } @Test - void testSendVideoMessage() throws IOException, URISyntaxException, InterruptedException { - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/message.json"))); - - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + void testSendVideoMessage() throws IOException, URISyntaxException, InterruptedException, JSONException { + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); + + var expectedJson = """ + { + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "video", + "video": { + "id": "78795489879879554", + "caption": "See the video" + } + } + """; var message = MessageBuilder.builder()// .setTo(PHONE_NUMBER_1)// @@ -195,25 +489,20 @@ void testSendVideoMessage() throws IOException, URISyntaxException, InterruptedE .setCaption("See the video")); - 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()); + // System.out.println(recordedRequest.getBody().readUtf8()); + JSONAssert.assertEquals(expectedJson, recordedRequest.getBody().readUtf8(), JSONCompareMode.STRICT); - Assertions.assertEquals(String.format("{\"messaging_product\":\"whatsapp\",\"recipient_type\":\"individual\",\"to\":\"%s\",\"type\":\"video\",\"video\":{\"id\":\"78795489879879554\",\"caption\":\"See the video\"}}", PHONE_NUMBER_1), recordedRequest.getBody().readUtf8()); - - Assertions.assertEquals("wamid.gBGGSFcCNEOPAgkO_KJ55r4w_ww", response.messages().get(0).id()); } @Test void testSendImageMessage() throws IOException, URISyntaxException, InterruptedException { - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/message.json"))); - - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); var message = MessageBuilder.builder()// .setTo(PHONE_NUMBER_1)// @@ -236,11 +525,7 @@ void testSendImageMessage() throws IOException, URISyntaxException, InterruptedE @Test void testSendDocumentMessage() throws IOException, URISyntaxException, InterruptedException { - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/message.json"))); - - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); var message = MessageBuilder.builder()// .setTo(PHONE_NUMBER_1)// @@ -263,11 +548,7 @@ void testSendDocumentMessage() throws IOException, URISyntaxException, Interrupt @Test void testSendStickerMessage() throws IOException, URISyntaxException, InterruptedException { - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/message.json"))); - - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_SEND_MESSAGE_RESPONSE)); var message = MessageBuilder.builder()// .setTo(PHONE_NUMBER_1)// @@ -291,10 +572,6 @@ void testSendStickerMessage() throws IOException, URISyntaxException, Interrupte void testUploadMedia() throws IOException, URISyntaxException, InterruptedException { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/uploadResponse.json"))); - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); - var fileContent = bytesFromResource("/starwars.png"); @@ -311,11 +588,6 @@ void testUploadMedia() throws IOException, URISyntaxException, InterruptedExcept void testRetrieveMediaUrl() throws IOException, URISyntaxException, InterruptedException { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/media.json"))); - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); - - var response = whatsappBusinessCloudApi.retrieveMediaUrl("1227829768162607"); RecordedRequest recordedRequest = mockWebServer.takeRequest(); @@ -334,10 +606,6 @@ void testRetrieveMediaUrl() throws IOException, URISyntaxException, InterruptedE void testDownloadMediaFile() throws InterruptedException, IOException, URISyntaxException { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/starwars.png")).setResponseCode(200).addHeader("Content-Disposition", "inline;filename=starwars.png")); - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); - var response = whatsappBusinessCloudApi.downloadMediaFile(baseUrl + "/whatsapp_business/attachments/?mid=1228169767822607&ext=16772107977&hash=ATs5BiSbLTZzCFh73M16stmnUK2UV6NBqChXB4WWC21sw"); RecordedRequest recordedRequest = mockWebServer.takeRequest(); @@ -354,9 +622,6 @@ void testDownloadMediaFile() throws InterruptedException, IOException, URISyntax void testDownloadMediaFileNotFound() throws InterruptedException { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(".").setResponseCode(404)); - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); var exception = Assertions.assertThrows(WhatsappApiException.class, () -> whatsappBusinessCloudApi.downloadMediaFile(baseUrl + "/whatsapp_business/attachments/?mid=1228169767822607&ext=16772107977&hash=ATs5BiSbLTZzCFh73M16stmnUK2UV6NBqChXB4WWC21sw")); RecordedRequest recordedRequest = mockWebServer.takeRequest(); @@ -371,11 +636,6 @@ void testDownloadMediaFileNotFound() throws InterruptedException { void testDeleteMedia() throws IOException, URISyntaxException, InterruptedException { mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/reponse.json"))); - WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TestConstants.TOKEN); - - WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); - - var response = whatsappBusinessCloudApi.deleteMedia("1227829768162607"); RecordedRequest recordedRequest = mockWebServer.takeRequest(); diff --git a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java index 1254ca5fa..fe21a1c53 100644 --- a/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java +++ b/src/test/java/com/whatsapp/api/impl/WhatsappBusinessManagementApiTest.java @@ -14,7 +14,9 @@ import com.whatsapp.api.domain.templates.FooterComponent; import com.whatsapp.api.domain.templates.HeaderComponent; import com.whatsapp.api.domain.templates.MessageTemplate; +import com.whatsapp.api.domain.templates.PhoneNumberButton; import com.whatsapp.api.domain.templates.QuickReplyButton; +import com.whatsapp.api.domain.templates.UrlButton; import com.whatsapp.api.domain.templates.type.Category; import com.whatsapp.api.domain.templates.type.HeaderFormat; import com.whatsapp.api.domain.templates.type.LanguageType; @@ -22,36 +24,75 @@ import com.whatsapp.api.utils.Formatter; import mockwebserver3.MockResponse; import mockwebserver3.RecordedRequest; +import org.json.JSONException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.skyscreamer.jsonassert.JSONAssert; +import org.skyscreamer.jsonassert.JSONCompareMode; import java.io.IOException; import java.net.URISyntaxException; +import java.util.Collections; -import static com.whatsapp.api.TestConstants.PHONE_NUMBER_ID; -import static com.whatsapp.api.TestConstants.TOKEN; -import static com.whatsapp.api.TestConstants.WABA_ID; import static com.whatsapp.api.configuration.WhatsappApiConfig.API_VERSION; class WhatsappBusinessManagementApiTest extends MockServerUtilsTest { + private final String PHONE_NUMBER_ID = "411001010101010"; + + private final String TOKEN = "54f6sd5f4654df21sdfs56d4fsd5f41f8we546F54f5dfF4FRDFGfGSHe54rf6sd5f4g55"; + + private final String WABA_ID = "57856727575875757"; + public final String DEFAULT_TEMPLATE_RESPONSE = """ + { + "status": "REJECTED", + "category": "UTILITY", + "id": "952305634123456" + } + """; /** * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testCreateMessageTemplate() throws IOException, URISyntaxException { + void testCreateMessageTemplate() throws InterruptedException, JSONException { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/template.json"))); - + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_TEMPLATE_RESPONSE)); + + var expectedJson = """ + { + "name": "welcome_template2", + "category": "UTILITY", + "components": [ + { + "format": "TEXT", + "type": "HEADER", + "text": "Wellcome title" + }, + { + "type": "BODY", + "text": "Hello {{1}}, welcome to our {{2}} test. ", + "example": { + "body_text": [ + [ + "Mr. José", + "s" + ] + ] + } + } + ], + "language": "en_US" + } + """; var template = new MessageTemplate(); template.setName("welcome_template2")// - .setCategory(Category.TRANSACTIONAL)// + .setCategory(Category.UTILITY)// .setLanguage(LanguageType.EN_US)// .addComponent(new HeaderComponent()// .setText("Wellcome title")// @@ -60,178 +101,345 @@ void testCreateMessageTemplate() throws IOException, URISyntaxException { .setText("Hello {{1}}, welcome to our {{2}} test. ")// .setExample(new Example()// .addBodyTextExamples("Mr. José", "s")// - ))// + )); + var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); - ; + var request = mockWebServer.takeRequest(); + Assertions.assertEquals("POST", request.getMethod()); + Assertions.assertEquals("/" + API_VERSION + "/" + WABA_ID + "/message_templates", request.getPath()); - var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); + JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); Assertions.assertEquals("952305634123456", response.id()); Assertions.assertEquals("REJECTED", response.status()); - Assertions.assertEquals(Category.TRANSACTIONAL, response.category()); + Assertions.assertEquals(Category.UTILITY, response.category()); } /** - * Method under test: {@link WhatsappBusinessManagementApi#updateMessageTemplate(String, String, MessageTemplate)} + * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testUpdateMessageTemplate() throws IOException, URISyntaxException { + void testCreateMessageTemplate2() throws IOException, URISyntaxException, InterruptedException, JSONException { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/template.json"))); + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_TEMPLATE_RESPONSE)); + + var expectedJson = fromResource("/expected/template/expectedTemplate1.json"); var template = new MessageTemplate(); - template.setName("welcome_template")// + template.setName("number_confirmation")// .setCategory(Category.TRANSACTIONAL)// - .setLanguage(LanguageType.EN_US)// + .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setText("Wellcome title")// + .setText("Código de confirmação")// .setFormat(HeaderFormat.TEXT))// .addComponent(new BodyComponent()// - .setText("Hello {{1}}, welcome to our {{2}} test. ")// + .setText("Este é o seu código de confirmação: " + Formatter.bold("{{1}}."))// .setExample(new Example()// - .addBodyTextExamples("Mr. José", "satisfaction")// + .addBodyTextExamples("1458425")// ))// + .addComponent(new FooterComponent().setText("Use este código para confirmar seu telefone.")); + whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); - ; + var request = mockWebServer.takeRequest(); + Assertions.assertEquals("POST", request.getMethod()); + Assertions.assertEquals("/" + API_VERSION + "/" + WABA_ID + "/message_templates", request.getPath()); - var response = whatsappBusinessCloudApi.updateMessageTemplate(WABA_ID, "952305634123456", template); + JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); - Assertions.assertEquals("952305634123456", response.id()); } - /** - * Method under test: {@link WhatsappBusinessManagementApi#deleteMessageTemplate(String, String)} + * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} */ @Test - void testDeleteMessageTemplate() throws IOException, URISyntaxException { + void testCreateMessageTemplate3() throws IOException, URISyntaxException, InterruptedException, JSONException { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_TEMPLATE_RESPONSE)); - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/deleteTemplate.json"))); + var expectedJson = fromResource("/expected/template/expectedTemplate2.json"); - var resp = whatsappBusinessCloudApi.deleteMessageTemplate(WABA_ID, "welcome_template"); + var template = new MessageTemplate(); - Assertions.assertTrue(resp.success()); + template.setName("schedule_confirmation3")// + .setCategory(Category.TRANSACTIONAL)// + .setLanguage(LanguageType.PT_BR)// + .addComponent(new HeaderComponent()// + .setText("Confirmação de Atendimento")// + .setFormat(HeaderFormat.TEXT))// + .addComponent(new BodyComponent()// + .setText("Olá " + Formatter.bold("{{1}}") + ", passando aqui para confirmar seu horário no dia " + Formatter.bold("{{2}}") + " as " + Formatter.bold("{{3}}h") + ".\nVocê confirma que comparecerá?")// + .setExample(new Example()// + .addBodyTextExamples("Maria", "04/11/2022", "13:30")// + ))// + .addComponent(new ButtonComponent()// + .addButton(new QuickReplyButton("SIM"))// + .addButton(new QuickReplyButton("NÃO"))// + .addButton(new QuickReplyButton("REMARCAR")// + ))// + .addComponent(new FooterComponent().setText("Utilize um dos botões abaixo para a confirmação")); - } + var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); + 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()); + JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); + } + /** + * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} + */ @Test - void testCreateMessageTemplate2() throws IOException, URISyntaxException { + void testCreateMessageTemplate4() throws IOException, URISyntaxException, InterruptedException, JSONException { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); - - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/template.json"))); - + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_TEMPLATE_RESPONSE)); + var expectedJson = fromResource("/expected/template/expectedTemplate4.json"); var template = new MessageTemplate(); - template.setName("number_confirmation")// + template.setName("schedule_confirmation5")// .setCategory(Category.TRANSACTIONAL)// .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setText("Código de confirmação")// + .setText("Confirmação de Atendimento")// .setFormat(HeaderFormat.TEXT))// .addComponent(new BodyComponent()// - .setText("Este é o seu código de confirmação: " + Formatter.bold("{{1}}."))// + .setText("Olá " + Formatter.bold("{{1}}") + ", passando aqui para confirmar seu horário no dia " + Formatter.bold("{{2}}") + " as " + Formatter.bold("{{3}}h") + ".\nVocê confirma que comparecerá?")// .setExample(new Example()// - .addBodyTextExamples("1458425")// + .addBodyTextExamples("Maria", "04/11/2022", "13:30")// ))// - .addComponent(new FooterComponent().setText("Use este código para confirmar seu telefone.")) - + .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"))// + ); - ; + whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); - var response = 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()); - Assertions.assertEquals("952305634123456", response.id()); + JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); } + /** + * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} + */ @Test - void testCreateMessageTemplate3() throws IOException, URISyntaxException { + void testCreateMessageTemplateUtility1() throws IOException, URISyntaxException, InterruptedException, JSONException { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/template.json"))); - + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_TEMPLATE_RESPONSE)); + var expectedJson = fromResource("/expected/template/expectedTemplate6.json"); var template = new MessageTemplate(); - template.setName("schedule_confirmation3")// - .setCategory(Category.TRANSACTIONAL)// + template.setName("new_classes_pdf_v2")// + .setCategory(Category.UTILITY)// .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setText("Confirmação de Atendimento")// - .setFormat(HeaderFormat.TEXT))// + .setFormat(HeaderFormat.DOCUMENT).setExample(new Example().addHeaderHandleExamples("4::aW1hZ2UvanBlZw==:ARb0a9E9s7-LdErXAXQCwyh7Oy-_h9gBo4ljPynnXo53CKOyyhHYUjCCREvS4fB-0CwfSQbNn9fJC3ikLOJve1CfQO-9aeWYdMmkMUJgGJI0g:e:1680011044:3449853982404722:100007529143136:ARZMcC4QfmCW8V85Lco")))// .addComponent(new BodyComponent()// - .setText("Olá " + Formatter.bold("{{1}}") + ", passando aqui para confirmar seu horário no dia " + Formatter.bold("{{2}}") + " as " + Formatter.bold("{{3}}h") + ".\nVocê confirma que comparecerá?")// + .setText("Olá {{1}}, seu professou publicou novas aulas na plataforma de ensino.")// .setExample(new Example()// - .addBodyTextExamples("Maria", "04/11/2022", "13:30")// + .addBodyTextExamples("Maria")// ))// + .addComponent(new FooterComponent().setText("Click on the button below to watch now"))// .addComponent(new ButtonComponent()// - .addButton(new QuickReplyButton("SIM"))// - .addButton(new QuickReplyButton("NÃO"))// - .addButton(new QuickReplyButton("REMARCAR")// - ) + .addButton(new UrlButton("Assistir agora")// + .setUrl("https://www.coursera.org/{{1}}")// + .setUrlExample(Collections.singletonList("https://www.coursera.org/?authMode=login"))// + )); + whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); - )// - .addComponent(new FooterComponent().setText("Utilize um dos botões abaixo para a confirmação")) + 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()); + + JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); + } + + /** + * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} + */ + @Test + void testCreateMessageTemplateUtility2() throws IOException, URISyntaxException, InterruptedException, JSONException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_TEMPLATE_RESPONSE)); + var expectedJson = fromResource("/expected/template/expectedTemplate8.json"); + var template = new MessageTemplate(); - ; + template.setName("call_to_me")// + .setCategory(Category.UTILITY)// + .setLanguage(LanguageType.PT_BR)// + .addComponent(new HeaderComponent()// + .setText("Problemas com a entrega do seu pedido")// + .setFormat(HeaderFormat.TEXT))// + .addComponent(new BodyComponent()// + .setText("Olá {{1}}, Tivemos um problema com a entrega do seu pedido {{2}}. Por favor, entre em contato com a central de atendimento para obter mais detalhes")// + .setExample(new Example()// + .addBodyTextExamples("Maria", "FE-15454T45001")))// + .addComponent(new ButtonComponent()// + .addButton(new PhoneNumberButton("Ligar agora", "16503087300"))// + )// + .addComponent(new FooterComponent().setText("Clique no botão abaixo para ligar agora.")); - var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); + whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); - Assertions.assertEquals("952305634123456", response.id()); + 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()); + + JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); } + /** + * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} + */ @Test - void testCreateMessageTemplate4() throws IOException, URISyntaxException { + void testCreateMessageTemplateAuthentication() throws IOException, URISyntaxException, InterruptedException, JSONException { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); - mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/template.json"))); + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_TEMPLATE_RESPONSE)); + var expectedJson = fromResource("/expected/template/expectedTemplate9.json"); + var template = new MessageTemplate(); + template.setName("auth_code_2")// + .setCategory(Category.AUTHENTICATION)// + .setLanguage(LanguageType.EN_US)// + .addComponent(new HeaderComponent()// + .setFormat(HeaderFormat.TEXT).setText("Your authentication code for {{1}}")// + .setExample(new Example().addHeaderTextExamples("App X")))// + .addComponent(new BodyComponent()// + .setText("Please use the code {{1}} to sign in to your account. Do not provide this code to third parties.")// + .setExample(new Example()// + .addBodyTextExamples("784-H45-7R4")))// + .addComponent(new FooterComponent().setText("Did you not request the code? Click on 'Not me'"))// + .addComponent(new ButtonComponent()// + .addButton(new QuickReplyButton("Not me"))// + ); + + 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()); + + JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); + } + + + /** + * Method under test: {@link WhatsappBusinessManagementApi#createMessageTemplate(String, MessageTemplate)} + */ + @Test + void testCreateMessageTemplateMarketing2() throws IOException, URISyntaxException, InterruptedException, JSONException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + + WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(DEFAULT_TEMPLATE_RESPONSE)); + var expectedJson = fromResource("/expected/template/expectedTemplate7.json"); var template = new MessageTemplate(); - template.setName("schedule_confirmation5")// - .setCategory(Category.TRANSACTIONAL)// + template.setName("marketing_coffee")// + .setCategory(Category.MARKETING)// .setLanguage(LanguageType.PT_BR)// .addComponent(new HeaderComponent()// - .setText("Confirmação de Atendimento")// - .setFormat(HeaderFormat.TEXT))// + .setFormat(HeaderFormat.IMAGE).setExample(new Example().addHeaderHandleExamples("4::aW1hZ2UvanBlZw==:ARZdpGlLrA9uwIGGZc-UFu5viAD1BkqTCYGL8je2d7xovDZphaWG8gJPTSJfekNchsL3SWdY8-jTA9ZRq_MWro-1wfJnApfbb0ByrUoDb6nNZA:e:1679805732:3449824985304722:100002914375136:ARauotmqlFdTcNENzt0")))// + .addComponent(new BodyComponent()// - .setText("Olá " + Formatter.bold("{{1}}") + ", passando aqui para confirmar seu horário no dia " + Formatter.bold("{{2}}") + " as " + Formatter.bold("{{3}}h") + ".\nVocê confirma que comparecerá?")// + .setText("Venha aproveitar nossos cafés especiais em nossa super promoção. Nossos expressos são a partir de R${{1}}")// .setExample(new Example()// - .addBodyTextExamples("Maria", "04/11/2022", "13:30")// + .addBodyTextExamples("15")// ))// .addComponent(new ButtonComponent()// - .addButton(new QuickReplyButton("SIM"))// - .addButton(new QuickReplyButton("NÃO"))// + .addButton(new QuickReplyButton("Saiba mais"))// + .addButton(new QuickReplyButton("Parar promoções")// + ))// + .addComponent(new FooterComponent().setText("Sem interesse? Clique em parar promoções")); - )// - .addComponent(new FooterComponent().setText("Utilize um dos botões abaixo para a confirmação")) + 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()); - var response = whatsappBusinessCloudApi.createMessageTemplate(WABA_ID, template); + JSONAssert.assertEquals(expectedJson, request.getBody().readUtf8(), JSONCompareMode.STRICT); + } + + /** + * Method under test: {@link WhatsappBusinessManagementApi#updateMessageTemplate(String, String, MessageTemplate)} + */ + @Test + void testUpdateMessageTemplate() throws IOException, URISyntaxException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + + WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/template.json"))); + + var template = new MessageTemplate(); + + template.setName("welcome_template")// + .setCategory(Category.TRANSACTIONAL)// + .setLanguage(LanguageType.EN_US)// + .addComponent(new HeaderComponent()// + .setText("Wellcome title")// + .setFormat(HeaderFormat.TEXT))// + .addComponent(new BodyComponent()// + .setText("Hello {{1}}, welcome to our {{2}} test. ")// + .setExample(new Example()// + .addBodyTextExamples("Mr. José", "satisfaction")// + )); + + var response = whatsappBusinessCloudApi.updateMessageTemplate(WABA_ID, "952305634123456", template); Assertions.assertEquals("952305634123456", response.id()); } + /** + * Method under test: {@link WhatsappBusinessManagementApi#deleteMessageTemplate(String, String)} + */ + @Test + void testDeleteMessageTemplate() throws IOException, URISyntaxException { + WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); + + WhatsappBusinessManagementApi whatsappBusinessCloudApi = factory.newBusinessManagementApi(); + + mockWebServer.enqueue(new MockResponse().setResponseCode(200).setBody(fromResource("/deleteTemplate.json"))); + + var resp = whatsappBusinessCloudApi.deleteMessageTemplate(WABA_ID, "welcome_template"); + + Assertions.assertTrue(resp.success()); + + } + @Test void testRetrieveMessageTemplate1() throws IOException, URISyntaxException { WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); @@ -413,7 +621,7 @@ void requestCodeError() throws IOException, URISyntaxException, InterruptedExcep Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/request_code", recordedRequest.getPath()); Assertions.assertEquals("{\"code_method\":\"SMS\",\"language\":\"en_US\"}", recordedRequest.getBody().readUtf8()); - Assertions.assertEquals("Request code error | Tente novamente depois de um tempo.", ex.getMessage()); + Assertions.assertEquals("[136024] Request code error | Tente novamente depois de um tempo.", ex.getMessage()); } @@ -457,7 +665,7 @@ void verifyCodeError() throws IOException, URISyntaxException, InterruptedExcept Assertions.assertEquals("/" + API_VERSION + "/" + PHONE_NUMBER_ID + "/verify_code", recordedRequest.getPath()); Assertions.assertEquals("{\"code\":\"12345678\"}", recordedRequest.getBody().readUtf8()); - Assertions.assertEquals("Verify code error | O código inserido está incorreto.", ex.getMessage()); + Assertions.assertEquals("[136025] Verify code error | O código inserido está incorreto.", ex.getMessage()); } diff --git a/src/test/resources/expected/message/expectedMessage1.json b/src/test/resources/expected/message/expectedMessage1.json new file mode 100644 index 000000000..1de8b01c1 --- /dev/null +++ b/src/test/resources/expected/message/expectedMessage1.json @@ -0,0 +1,10 @@ +{ + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "text", + "text": { + "preview_url": false, + "body": "*Hello world!*\nSome code here: \n```hello world code here```" + } +} \ No newline at end of file diff --git a/src/test/resources/expected/message/expectedMessage2.json b/src/test/resources/expected/message/expectedMessage2.json new file mode 100644 index 000000000..e6002f91d --- /dev/null +++ b/src/test/resources/expected/message/expectedMessage2.json @@ -0,0 +1,23 @@ +{ + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "template", + "template": { + "components": [ + { + "type": "body", + "parameters": [ + { + "type": "text", + "text": "18754269072" + } + ] + } + ], + "name": "number_confirmation", + "language": { + "code": "pt_BR" + } + } +} \ No newline at end of file diff --git a/src/test/resources/expected/message/expectedMessage3.json b/src/test/resources/expected/message/expectedMessage3.json new file mode 100644 index 000000000..0441c2bc2 --- /dev/null +++ b/src/test/resources/expected/message/expectedMessage3.json @@ -0,0 +1,64 @@ +{ + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "template", + "template": { + "components": [ + { + "type": "body", + "parameters": [ + { + "type": "text", + "text": "Mauricio" + }, + { + "type": "text", + "text": "04/11/2022" + }, + { + "type": "text", + "text": "14:30" + } + ] + }, + { + "type": "button", + "parameters": [ + { + "type": "payload", + "payload": "OP_YES_48547" + } + ], + "index": 0, + "sub_type": "quick_reply" + }, + { + "type": "button", + "parameters": [ + { + "type": "payload", + "payload": "OP_NO_48548" + } + ], + "index": 1, + "sub_type": "quick_reply" + }, + { + "type": "button", + "parameters": [ + { + "type": "payload", + "payload": "OP_CH_48549" + } + ], + "index": 2, + "sub_type": "quick_reply" + } + ], + "name": "schedule_confirmation3", + "language": { + "code": "pt_BR" + } + } +} \ No newline at end of file diff --git a/src/test/resources/expected/message/expectedMessage4.json b/src/test/resources/expected/message/expectedMessage4.json new file mode 100644 index 000000000..b1b57ff07 --- /dev/null +++ b/src/test/resources/expected/message/expectedMessage4.json @@ -0,0 +1,77 @@ +{ + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "template", + "template": { + "components": [ + { + "type": "body", + "parameters": [ + { + "type": "text", + "text": "Mauricio" + }, + { + "type": "date_time", + "date_time": { + "fallback_value": "25/03/2023", + "calendar": "GREGORIAN", + "month": 3, + "hour": 13, + "year": 2023, + "day_of_month": 25, + "day_of_week": 7, + "minute": 50 + } + }, + { + "type": "date_time", + "date_time": { + "fallback_value": "14:34", + "hour": 14, + "minute": 30 + } + } + ] + }, + { + "type": "button", + "parameters": [ + { + "type": "payload", + "payload": "OP_YES_48547" + } + ], + "index": 0, + "sub_type": "quick_reply" + }, + { + "type": "button", + "parameters": [ + { + "type": "payload", + "payload": "OP_NO_48548" + } + ], + "index": 1, + "sub_type": "quick_reply" + }, + { + "type": "button", + "parameters": [ + { + "type": "payload", + "payload": "OP_CH_48549" + } + ], + "index": 2, + "sub_type": "quick_reply" + } + ], + "name": "schedule_confirmation3", + "language": { + "code": "pt_BR" + } + } +} \ No newline at end of file diff --git a/src/test/resources/expected/message/expectedMessage5.json b/src/test/resources/expected/message/expectedMessage5.json new file mode 100644 index 000000000..c77b19201 --- /dev/null +++ b/src/test/resources/expected/message/expectedMessage5.json @@ -0,0 +1,73 @@ +{ + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "template", + "template": { + "components": [ + { + "type": "header", + "parameters": [ + { + "type": "image", + "image": { + "id": "3196424913981611" + } + } + ] + }, + { + "type": "body", + "parameters": [ + { + "type": "date_time", + "date_time": { + "fallback_value": "May 10th, 2023", + "calendar": "GREGORIAN", + "month": 3, + "hour": 10, + "year": 2023, + "day_of_month": 26, + "day_of_week": 1, + "minute": 50 + } + }, + { + "type": "currency", + "currency": { + "fallback_value": "$35", + "code": "USD", + "amount_1000": 30000 + } + } + ] + }, + { + "type": "button", + "parameters": [ + { + "type": "payload", + "payload": "OP_SHN_454584" + } + ], + "index": 0, + "sub_type": "quick_reply" + }, + { + "type": "button", + "parameters": [ + { + "type": "payload", + "payload": "OP_SPR_454585" + } + ], + "index": 1, + "sub_type": "quick_reply" + } + ], + "name": "marketing_music_2", + "language": { + "code": "en_US" + } + } +} \ No newline at end of file diff --git a/src/test/resources/expected/message/expectedMessage6.json b/src/test/resources/expected/message/expectedMessage6.json new file mode 100644 index 000000000..29d3ea80a --- /dev/null +++ b/src/test/resources/expected/message/expectedMessage6.json @@ -0,0 +1,46 @@ +{ + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "template", + "template": { + "components": [ + { + "type": "header", + "parameters": [ + { + "document": { + "id": "928860901494862", + "filename": "Class.pdf" + }, + "type": "document" + } + ] + }, + { + "type": "body", + "parameters": [ + { + "type": "text", + "text": "Mauricio Binda" + } + ] + }, + { + "type": "button", + "parameters": [ + { + "type": "text", + "text": "career-academy/?trk_ref=globalnav" + } + ], + "index": 0, + "sub_type": "url" + } + ], + "name": "new_classes_pdf", + "language": { + "code": "en_US" + } + } +} \ No newline at end of file diff --git a/src/test/resources/expected/message/expectedMessage7.json b/src/test/resources/expected/message/expectedMessage7.json new file mode 100644 index 000000000..892ae1e02 --- /dev/null +++ b/src/test/resources/expected/message/expectedMessage7.json @@ -0,0 +1,9 @@ +{ + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "audio", + "audio": { + "id": "4545454545454" + } +} \ No newline at end of file diff --git a/src/test/resources/expected/message/expectedMessage8.json b/src/test/resources/expected/message/expectedMessage8.json new file mode 100644 index 000000000..b3e0a94f9 --- /dev/null +++ b/src/test/resources/expected/message/expectedMessage8.json @@ -0,0 +1,34 @@ +{ + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "template", + "template": { + "components": [ + { + "type": "header", + "parameters": [ + { + "type": "video", + "video": { + "id": "4548775454857854" + } + } + ] + }, + { + "type": "body", + "parameters": [ + { + "type": "text", + "text": "Mauricio Binda" + } + ] + } + ], + "name": "video_tm", + "language": { + "code": "en_US" + } + } +} \ No newline at end of file diff --git a/src/test/resources/expected/message/expectedMessage9.json b/src/test/resources/expected/message/expectedMessage9.json new file mode 100644 index 000000000..39bed325e --- /dev/null +++ b/src/test/resources/expected/message/expectedMessage9.json @@ -0,0 +1,34 @@ +{ + "messaging_product": "whatsapp", + "recipient_type": "individual", + "to": "121212121212", + "type": "template", + "template": { + "components": [ + { + "type": "header", + "parameters": [ + { + "type": "image", + "image": { + "id": "554066036582230" + } + } + ] + }, + { + "type": "body", + "parameters": [ + { + "type": "text", + "text": "T87-G74-876" + } + ] + } + ], + "name": "auth_app", + "language": { + "code": "pt_BR" + } + } +} \ No newline at end of file diff --git a/src/test/resources/expected/template/expectedTemplate1.json b/src/test/resources/expected/template/expectedTemplate1.json new file mode 100644 index 000000000..63ffc62c6 --- /dev/null +++ b/src/test/resources/expected/template/expectedTemplate1.json @@ -0,0 +1,27 @@ +{ + "name": "number_confirmation", + "category": "TRANSACTIONAL", + "components": [ + { + "format": "TEXT", + "type": "HEADER", + "text": "Código de confirmação" + }, + { + "type": "BODY", + "text": "Este é o seu código de confirmação: *{{1}}.*", + "example": { + "body_text": [ + [ + "1458425" + ] + ] + } + }, + { + "type": "FOOTER", + "text": "Use este código para confirmar seu telefone." + } + ], + "language": "pt_BR" +} \ No newline at end of file diff --git a/src/test/resources/expected/template/expectedTemplate2.json b/src/test/resources/expected/template/expectedTemplate2.json new file mode 100644 index 000000000..4fe9490e8 --- /dev/null +++ b/src/test/resources/expected/template/expectedTemplate2.json @@ -0,0 +1,46 @@ +{ + "name": "schedule_confirmation3", + "category": "TRANSACTIONAL", + "components": [ + { + "format": "TEXT", + "type": "HEADER", + "text": "Confirmação de Atendimento" + }, + { + "type": "BODY", + "text": "Olá *{{1}}*, passando aqui para confirmar seu horário no dia *{{2}}* as *{{3}}h*.\nVocê confirma que comparecerá?", + "example": { + "body_text": [ + [ + "Maria", + "04/11/2022", + "13:30" + ] + ] + } + }, + { + "buttons": [ + { + "type": "QUICK_REPLY", + "text": "SIM" + }, + { + "type": "QUICK_REPLY", + "text": "NÃO" + }, + { + "type": "QUICK_REPLY", + "text": "REMARCAR" + } + ], + "type": "BUTTONS" + }, + { + "type": "FOOTER", + "text": "Utilize um dos botões abaixo para a confirmação" + } + ], + "language": "pt_BR" +} \ No newline at end of file diff --git a/src/test/resources/expected/template/expectedTemplate4.json b/src/test/resources/expected/template/expectedTemplate4.json new file mode 100644 index 000000000..9584ab6bb --- /dev/null +++ b/src/test/resources/expected/template/expectedTemplate4.json @@ -0,0 +1,42 @@ +{ + "name": "schedule_confirmation5", + "category": "TRANSACTIONAL", + "components": [ + { + "format": "TEXT", + "type": "HEADER", + "text": "Confirmação de Atendimento" + }, + { + "type": "BODY", + "text": "Olá *{{1}}*, passando aqui para confirmar seu horário no dia *{{2}}* as *{{3}}h*.\nVocê confirma que comparecerá?", + "example": { + "body_text": [ + [ + "Maria", + "04/11/2022", + "13:30" + ] + ] + } + }, + { + "type": "FOOTER", + "text": "Utilize um dos botões abaixo para a confirmação" + }, + { + "buttons": [ + { + "type": "QUICK_REPLY", + "text": "SIM" + }, + { + "type": "QUICK_REPLY", + "text": "NÃO" + } + ], + "type": "BUTTONS" + } + ], + "language": "pt_BR" +} \ No newline at end of file diff --git a/src/test/resources/expected/template/expectedTemplate5.json b/src/test/resources/expected/template/expectedTemplate5.json new file mode 100644 index 000000000..c7426b156 --- /dev/null +++ b/src/test/resources/expected/template/expectedTemplate5.json @@ -0,0 +1,45 @@ +{ + "name": "marketing_music_878", + "category": "MARKETING", + "components": [ + { + "format": "IMAGE", + "type": "HEADER", + "example": { + "header_handle": [ + "4::aW1hZ2UvanBlZw==:ARZdpGlLrA9uwIGGZc-UFu5viAD1BkqTCYGL8je2d7xovDZphaWG8gJPTSJfekNchsL3SWdY8-jTA9ZRq_MWro-1wfJnApfbb0ByrUoDb6nNZA:e:1679805732:3449498285304722:100002149375136:ARauotTcmqlFdNENzt0" + ] + } + }, + { + "type": "BODY", + "text": "Join us for our live music event on {{1}}. You can get a ticket for only ${{2}}. Thanks.", + "example": { + "body_text": [ + [ + "May 10th, 2023", + "30" + ] + ] + } + }, + { + "buttons": [ + { + "type": "QUICK_REPLY", + "text": "Shop Now" + }, + { + "type": "QUICK_REPLY", + "text": "Stop promotions" + } + ], + "type": "BUTTONS" + }, + { + "type": "FOOTER", + "text": "Not interested? Tap Stop promotions" + } + ], + "language": "en_US" +} \ No newline at end of file diff --git a/src/test/resources/expected/template/expectedTemplate6.json b/src/test/resources/expected/template/expectedTemplate6.json new file mode 100644 index 000000000..8d122d0a3 --- /dev/null +++ b/src/test/resources/expected/template/expectedTemplate6.json @@ -0,0 +1,44 @@ +{ + "name": "new_classes_pdf_v2", + "category": "UTILITY", + "components": [ + { + "format": "DOCUMENT", + "type": "HEADER", + "example": { + "header_handle": [ + "4::aW1hZ2UvanBlZw==:ARb0a9E9s7-LdErXAXQCwyh7Oy-_h9gBo4ljPynnXo53CKOyyhHYUjCCREvS4fB-0CwfSQbNn9fJC3ikLOJve1CfQO-9aeWYdMmkMUJgGJI0g:e:1680011044:3449853982404722:100007529143136:ARZMcC4QfmCW8V85Lco" + ] + } + }, + { + "type": "BODY", + "text": "Olá {{1}}, seu professou publicou novas aulas na plataforma de ensino.", + "example": { + "body_text": [ + [ + "Maria" + ] + ] + } + }, + { + "type": "FOOTER", + "text": "Click on the button below to watch now" + }, + { + "buttons": [ + { + "type": "URL", + "text": "Assistir agora", + "url": "https://www.coursera.org/{{1}}", + "example": [ + "https://www.coursera.org/?authMode=login" + ] + } + ], + "type": "BUTTONS" + } + ], + "language": "pt_BR" +} \ No newline at end of file diff --git a/src/test/resources/expected/template/expectedTemplate7.json b/src/test/resources/expected/template/expectedTemplate7.json new file mode 100644 index 000000000..c4b74773c --- /dev/null +++ b/src/test/resources/expected/template/expectedTemplate7.json @@ -0,0 +1,44 @@ +{ + "name": "marketing_coffee", + "category": "MARKETING", + "components": [ + { + "format": "IMAGE", + "type": "HEADER", + "example": { + "header_handle": [ + "4::aW1hZ2UvanBlZw==:ARZdpGlLrA9uwIGGZc-UFu5viAD1BkqTCYGL8je2d7xovDZphaWG8gJPTSJfekNchsL3SWdY8-jTA9ZRq_MWro-1wfJnApfbb0ByrUoDb6nNZA:e:1679805732:3449824985304722:100002914375136:ARauotmqlFdTcNENzt0" + ] + } + }, + { + "type": "BODY", + "text": "Venha aproveitar nossos cafés especiais em nossa super promoção. Nossos expressos são a partir de R${{1}}", + "example": { + "body_text": [ + [ + "15" + ] + ] + } + }, + { + "buttons": [ + { + "type": "QUICK_REPLY", + "text": "Saiba mais" + }, + { + "type": "QUICK_REPLY", + "text": "Parar promoções" + } + ], + "type": "BUTTONS" + }, + { + "type": "FOOTER", + "text": "Sem interesse? Clique em parar promoções" + } + ], + "language": "pt_BR" +} \ No newline at end of file diff --git a/src/test/resources/expected/template/expectedTemplate8.json b/src/test/resources/expected/template/expectedTemplate8.json new file mode 100644 index 000000000..f4fce92f3 --- /dev/null +++ b/src/test/resources/expected/template/expectedTemplate8.json @@ -0,0 +1,38 @@ +{ + "name": "call_to_me", + "category": "UTILITY", + "components": [ + { + "format": "TEXT", + "type": "HEADER", + "text": "Problemas com a entrega do seu pedido" + }, + { + "type": "BODY", + "text": "Olá {{1}}, Tivemos um problema com a entrega do seu pedido {{2}}. Por favor, entre em contato com a central de atendimento para obter mais detalhes", + "example": { + "body_text": [ + [ + "Maria", + "FE-15454T45001" + ] + ] + } + }, + { + "buttons": [ + { + "type": "PHONE_NUMBER", + "text": "Ligar agora", + "phone_number": "16503087300" + } + ], + "type": "BUTTONS" + }, + { + "type": "FOOTER", + "text": "Clique no botão abaixo para ligar agora." + } + ], + "language": "pt_BR" +} \ No newline at end of file diff --git a/src/test/resources/expected/template/expectedTemplate9.json b/src/test/resources/expected/template/expectedTemplate9.json new file mode 100644 index 000000000..2a59b9e2c --- /dev/null +++ b/src/test/resources/expected/template/expectedTemplate9.json @@ -0,0 +1,41 @@ +{ + "name": "auth_code_2", + "category": "AUTHENTICATION", + "components": [ + { + "format": "TEXT", + "type": "HEADER", + "text": "Your authentication code for {{1}}", + "example": { + "header_text": [ + "App X" + ] + } + }, + { + "type": "BODY", + "text": "Please use the code {{1}} to sign in to your account. Do not provide this code to third parties.", + "example": { + "body_text": [ + [ + "784-H45-7R4" + ] + ] + } + }, + { + "type": "FOOTER", + "text": "Did you not request the code? Click on 'Not me'" + }, + { + "buttons": [ + { + "type": "QUICK_REPLY", + "text": "Not me" + } + ], + "type": "BUTTONS" + } + ], + "language": "en_US" +} \ No newline at end of file diff --git a/src/test/resources/template.json b/src/test/resources/template.json index f45dd9c15..6ea41a6be 100644 --- a/src/test/resources/template.json +++ b/src/test/resources/template.json @@ -1,5 +1,5 @@ { "status": "REJECTED", - "category": "TRANSACTIONAL", + "category": "UTILITY", "id": "952305634123456" } \ No newline at end of file