Skip to content

Commit

Permalink
Merge pull request #63 from Bindambc/40-message-template
Browse files Browse the repository at this point in the history
Changes to message template creation and changes to message template sending.
  • Loading branch information
Bindambc authored Mar 26, 2023
2 parents 2aeafb2 + 10bbfee commit 5b1de53
Show file tree
Hide file tree
Showing 63 changed files with 3,052 additions and 409 deletions.
14 changes: 9 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
<artifactId>converter-jackson</artifactId>
<version>${com.squareup.retrofit2.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${com.squareup.okhttp3.version}</version>
</dependency>
<!--tests-->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down Expand Up @@ -88,12 +93,11 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>${com.squareup.okhttp3.version}</version>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.1</version>
<scope>test</scope>
</dependency>


</dependencies>

<build>
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/whatsapp/api/domain/messages/BodyComponent.java
Original file line number Diff line number Diff line change
@@ -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<BodyComponent> {


/**
* Instantiates a new Body component, to send template messages
*/
public BodyComponent() {
super(ComponentType.BODY);
}


}
Original file line number Diff line number Diff line change
@@ -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<ButtonComponent> {
@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;
}
}
Original file line number Diff line number Diff line change
@@ -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 <a href="https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages#button-parameter-object">Api reference</a>
*/
@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;
}
}
Original file line number Diff line number Diff line change
@@ -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 <a href="https://developers.facebook.com/docs/whatsapp/cloud-api/reference/messages#button-parameter-object">Api reference</a>
*/
@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. <b>Required for URL buttons</b>. 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. <b>Required for URL buttons</b>. 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;
}
}
24 changes: 19 additions & 5 deletions src/main/java/com/whatsapp/api/domain/messages/Component.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
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;

/**
* 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<T extends Component<T>> {
@JsonProperty("type")
private final ComponentType type;
@JsonProperty("parameters")
private List<Parameter> parameters;


/**
* Instantiates a new Component.
*
* @param type the type
*/
public Component(ComponentType type) {
@JsonCreator
protected Component(ComponentType type) {
this.type = type;
}

Expand Down Expand Up @@ -48,7 +62,7 @@ public List<Parameter> getParameters() {
* @param parameters the parameters
* @return the parameters
*/
public Component setParameters(List<Parameter> parameters) {
public Component<T> setParameters(List<Parameter> parameters) {
this.parameters = parameters;
return this;
}
Expand All @@ -59,7 +73,7 @@ public Component setParameters(List<Parameter> parameters) {
* @param parameter the parameter
* @return the component
*/
public Component addParameter(Parameter parameter) {
public Component<T> addParameter(Parameter parameter) {
if (this.parameters == null) this.parameters = new ArrayList<>();

this.parameters.add(parameter);
Expand Down
Loading

0 comments on commit 5b1de53

Please sign in to comment.