Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for interactive whatsapp messages #274

Merged
merged 6 commits into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [5.41.0](https://github.com/plivo/plivo-java/tree/v5.41.0) (2024-05-07)
**Feature - Adding support for interactive whatsapp messages**
- Added new param `interactive` to [send message API](https://www.plivo.com/docs/sms/api/message#send-a-message) to support interactive `whatsapp` messages

## [5.40.0](https://github.com/plivo/plivo-java/tree/v5.40.0) (2023-04-18)
**Feature - Support for dynamic button components when sending a templated WhatsApp message**
- Added new param `payload` in templates to support dynamic payload in templates
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ The Plivo Java SDK makes it simpler to integrate communications into your Java a

### To Install Stable release

You can use this SDK by adding it as a dependency in your dependency management tool. Alternatively, you can use the [JAR file](https://search.maven.org/remotecontent?filepath=com/plivo/plivo-java/5.40.0/plivo-java-5.40.0.jar).
You can use this SDK by adding it as a dependency in your dependency management tool. Alternatively, you can use the [JAR file](https://search.maven.org/remotecontent?filepath=com/plivo/plivo-java/5.41.0/plivo-java-5.41.0.jar).


If you are using Maven, use the following XML to include the Plivo SDK as a dependency.
Expand All @@ -19,13 +19,13 @@ If you are using Maven, use the following XML to include the Plivo SDK as a depe
<dependency>
<groupId>com.plivo</groupId>
<artifactId>plivo-java</artifactId>
<version>5.40.0</version>
<version>5.41.0</version>
</dependency>
```

If you are using Gradle, use the following line in your dependencies.
```
compile 'com.plivo:plivo-java:5.40.0'
compile 'com.plivo:plivo-java:5.41.0'
```

### To Install Beta release
Expand Down
2 changes: 1 addition & 1 deletion pom.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Written manually.

version=5.40.0
version=5.41.0
groupId=com.plivo
artifactId=plivo-java

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.plivo</groupId>
<artifactId>plivo-java</artifactId>
<version>5.40.0</version>
<version>5.41.0</version>
<name>plivo-java</name>
<description>A Java SDK to make voice calls &amp; send SMS using Plivo and to generate Plivo XML</description>
<licenses>
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/com/plivo/api/models/message/Action.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.plivo.api.models.message;

import java.util.List;

public class Action {
private List<Button> buttons; // List of buttons for multiple options
private List<Section> sections; // List of sections

public Action() {
}

// Getters and setters for buttons
public List<Button> getButtons() {
return buttons;
}

public void setButtons(List<Button> buttons) {
this.buttons = buttons;
}

// Getters and setters for sections
public List<Section> getSections() {
return sections;
}

public void setSections(List<Section> sections) {
this.sections = sections;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/plivo/api/models/message/Body.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.plivo.api.models.message;

public class Body {
private String text;

public Body() {
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}
}
37 changes: 37 additions & 0 deletions src/main/java/com/plivo/api/models/message/Button.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.plivo.api.models.message;

public class Button {
private String id; // Unique identifier for the button
private String title; // Display text for the button
private String cta_url;

public Button() {
}

// Getters and setters for ID
public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

// Getters and setters for Title
public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

// Getters and setters for CTA URL
public String getCta_url() {
return cta_url;
}

public void setCta_url(String cta_url) {
this.cta_url = cta_url;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/plivo/api/models/message/Footer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.plivo.api.models.message;

public class Footer {
private String text;

public Footer() {
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}
}
35 changes: 35 additions & 0 deletions src/main/java/com/plivo/api/models/message/Header.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.plivo.api.models.message;

public class Header {
private String type;
private String text;
private String media;

public Header() {
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public String getMedia() {
return media;
}

public void setMedia(String media) {
this.media = media;
}

}
58 changes: 58 additions & 0 deletions src/main/java/com/plivo/api/models/message/Interactive.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.plivo.api.models.message;

import java.util.List;

public class Interactive {
private String type;
private Header header;
private Body body;
private Footer footer;
private Action action;

public Interactive() {
}

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public Header getHeader() {
return header;
}

public void setHeader(Header header) {
this.header = header;
}

public Body getBody() {
return body;
}

public void setBody(Body body) {
this.body = body;
}

public Footer getFooter() {
return footer;
}

public void setFooter(Footer footer) {
this.footer = footer;
}

public Action getAction() {
return action;
}

public void setAction(Action action) {
this.action = action;
}
}




45 changes: 45 additions & 0 deletions src/main/java/com/plivo/api/models/message/MessageCreator.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public class MessageCreator extends Creator < MessageCreateResponse > {
private String dlt_template_category;
@JsonProperty("template")
private Template template;
@JsonProperty("interactive")
private Interactive interactive;

/**
* @param source The phone number that will be shown as the sender ID.
Expand Down Expand Up @@ -309,6 +311,49 @@ public MessageCreator template(final Template temp) {
return this;
}


/**
* @param intractv This is the interactive messages passed as a interactive object in the whatsapp message request.
*/
public MessageCreator interactive(final Interactive intractv) {
if (type == null) {
this.type = MessageType.WHATSAPP;
} else {
if (type.equals(MessageType.SMS) || (type.equals(MessageType.MMS)))
throw new IllegalArgumentException("type parameter should be whatsapp");
}
if (Utils.allNotNull(this.interactive)) {
throw new IllegalArgumentException("interacitve parameter is already set");
}
this.interactive = intractv;

return this;
}

/**
* @param interactive_json_string This is the interactive message passed as a json string in the whatsapp message request.
*/
public MessageCreator interactive_json_string(final String interactive_json_string) {
if (this.type == null) {
this.type = MessageType.WHATSAPP;
} else {
if (this.type.equals(MessageType.SMS) || (this.type.equals(MessageType.MMS)))
throw new IllegalArgumentException("type parameter should be whatsapp");
}
if (Utils.allNotNull(this.interactive)) {
throw new IllegalArgumentException("interactive parameter is already set");
}
try {
ObjectMapper objectMapper = new ObjectMapper();
Interactive parsedInteractive = objectMapper.readValue(interactive_json_string, Interactive.class);
this.interactive = parsedInteractive;
} catch (Exception e) {
e.printStackTrace();
throw new IllegalArgumentException("failed to read interactive message");
}
return this;
}

@Override
protected Call < MessageCreateResponse > obtainCall() {
return client().getApiService().messageSend(client().getAuthId(), this);
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/plivo/api/models/message/Parameter.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ public DateTime getDate_time() {
public void setDate_time(DateTime date_time) {
this.date_time = date_time;
}

}
34 changes: 34 additions & 0 deletions src/main/java/com/plivo/api/models/message/Row.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.plivo.api.models.message;

public class Row {
private String id;
private String title;
private String description;

public Row() {
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/plivo/api/models/message/Section.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.plivo.api.models.message;

import java.util.List;

public class Section {
private String title;
private List<Row> rows;

public Section() {
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public List<Row> getRows() {
return rows;
}

public void setRows(List<Row> rows) {
this.rows = rows;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/com/plivo/api/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.40.0
5.41.0
Loading