diff --git a/src/main/java/com/whatsapp/api/domain/messages/Context.java b/src/main/java/com/whatsapp/api/domain/messages/Context.java
new file mode 100644
index 000000000..8a6a265b6
--- /dev/null
+++ b/src/main/java/com/whatsapp/api/domain/messages/Context.java
@@ -0,0 +1,33 @@
+package com.whatsapp.api.domain.messages;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Object that allow messages to be replied
+ *
+ *
+ * @see Replies
+*/
+@JsonInclude(JsonInclude.Include.NON_NULL)
+public class Context {
+
+ @JsonProperty("message_id")
+ private String messageId;
+
+ /**
+ * Gets messageId.
+ *
+ * @return the messageId
+ */
+ public String getMessageId() {
+ return messageId;
+ }
+
+ /**
+ * Sets messageId.
+ */
+ public void setMessageId(String messageId) {
+ this.messageId = messageId;
+ }
+}
diff --git a/src/main/java/com/whatsapp/api/domain/messages/Message.java b/src/main/java/com/whatsapp/api/domain/messages/Message.java
index 9e10e4558..0b1f4bde3 100644
--- a/src/main/java/com/whatsapp/api/domain/messages/Message.java
+++ b/src/main/java/com/whatsapp/api/domain/messages/Message.java
@@ -17,6 +17,8 @@ public class Message {
private final String messagingProduct = "whatsapp";
@JsonProperty("recipient_type")
private final String recipientType = "individual";
+ @JsonProperty("context")
+ private Context context;
/**
* The Interactive message.
*/
@@ -58,9 +60,10 @@ public class Message {
private Message() {
}
- private Message(String to, MessageType type) {
+ private Message(String to, MessageType type, Context context) {
this.to = to;
this.type = type;
+ this.context = context;
}
/**
@@ -81,12 +84,22 @@ public String getRecipientType() {
return recipientType;
}
+ /**
+ * Gets context.
+ *
+ * @return the context
+ */
+ public Context getContext() {
+ return context;
+ }
+
/**
* The type Message builder.
*/
public static class MessageBuilder {
private String to;
+ private Context context;
private MessageBuilder() {
@@ -112,6 +125,17 @@ public MessageBuilder setTo(String to) {
return this;
}
+ /**
+ * Sets context.
+ *
+ * @param context. the messsage's context.
+ * @return the context
+ */
+ public MessageBuilder setContext(Context context) {
+ this.context = context;
+ return this;
+ }
+
/**
* Build a text objetc, with:
*
@@ -123,7 +147,7 @@ public MessageBuilder setTo(String to) {
* @return the message
*/
public Message buildTextMessage(TextMessage textMessage) {
- var message = new Message(to, MessageType.TEXT);
+ var message = new Message(to, MessageType.TEXT, context);
message.textMessage = textMessage;
return message;
@@ -139,7 +163,7 @@ public Message buildTextMessage(TextMessage textMessage) {
* @see API documentation
*/
public Message buildContactMessage(ContactMessage contactMessage) {
- var message = new Message(to, MessageType.CONTACTS);
+ var message = new Message(to, MessageType.CONTACTS, context);
message.contactMessage = contactMessage.getContacts();
return message;
@@ -153,7 +177,7 @@ public Message buildContactMessage(ContactMessage contactMessage) {
* @see API documentation
*/
public Message buildTemplateMessage(TemplateMessage templateMessage) {
- var message = new Message(to, MessageType.TEMPLATE);
+ var message = new Message(to, MessageType.TEMPLATE, context);
message.templateMessage = templateMessage;
return message;
@@ -167,7 +191,7 @@ public Message buildTemplateMessage(TemplateMessage templateMessage) {
* @see API documentation
*/
public Message buildInteractiveMessage(InteractiveMessage interactiveMessage) {
- var message = new Message(to, MessageType.INTERACTIVE);
+ var message = new Message(to, MessageType.INTERACTIVE, context);
message.interactiveMessage = interactiveMessage;
return message;
@@ -182,7 +206,7 @@ public Message buildInteractiveMessage(InteractiveMessage interactiveMessage) {
* @see API documentation
*/
public Message buildAudioMessage(AudioMessage audioMessage) {
- var message = new Message(to, MessageType.AUDIO);
+ var message = new Message(to, MessageType.AUDIO, context);
message.audioMessage = audioMessage;
return message;
@@ -196,7 +220,7 @@ public Message buildAudioMessage(AudioMessage audioMessage) {
* @see API documentation
*/
public Message buildDocumentMessage(DocumentMessage documentMessage) {
- var message = new Message(to, MessageType.DOCUMENT);
+ var message = new Message(to, MessageType.DOCUMENT, context);
message.documentMessage = documentMessage;
return message;
@@ -210,7 +234,7 @@ public Message buildDocumentMessage(DocumentMessage documentMessage) {
* @see API documentation
*/
public Message buildImageMessage(ImageMessage imageMessage) {
- var message = new Message(to, MessageType.IMAGE);
+ var message = new Message(to, MessageType.IMAGE, context);
message.imageMessage = imageMessage;
return message;
@@ -224,7 +248,7 @@ public Message buildImageMessage(ImageMessage imageMessage) {
* @see API documentation
*/
public Message buildStickerMessage(StickerMessage stickerMessage) {
- var message = new Message(to, MessageType.STICKER);
+ var message = new Message(to, MessageType.STICKER, context);
message.stickerMessage = stickerMessage;
return message;
@@ -238,7 +262,7 @@ public Message buildStickerMessage(StickerMessage stickerMessage) {
* @see API documentation
*/
public Message buildVideoMessage(VideoMessage videoMessage) {
- var message = new Message(to, MessageType.VIDEO);
+ var message = new Message(to, MessageType.VIDEO, context);
message.videoMessage = videoMessage;
return message;
@@ -252,7 +276,7 @@ public Message buildVideoMessage(VideoMessage videoMessage) {
* @see API documentation
*/
public Message buildReactionMessage(ReactionMessage reactionMessage) {
- var message = new Message(to, MessageType.REACTION);
+ var message = new Message(to, MessageType.REACTION, context);
message.reactionMessage = reactionMessage;
return message;
@@ -266,7 +290,7 @@ public Message buildReactionMessage(ReactionMessage reactionMessage) {
* @see API documentation
*/
public Message buildLocationMessage(LocationMessage locationMessage) {
- var message = new Message(to, MessageType.LOCATION);
+ var message = new Message(to, MessageType.LOCATION, context);
message.locationMessage = locationMessage;
return message;
diff --git a/src/test/java/com/whatsapp/api/domain/messages/MessageTest.java b/src/test/java/com/whatsapp/api/domain/messages/MessageTest.java
new file mode 100644
index 000000000..a5e0aac6c
--- /dev/null
+++ b/src/test/java/com/whatsapp/api/domain/messages/MessageTest.java
@@ -0,0 +1,33 @@
+package com.whatsapp.api.domain.messages;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.junit.jupiter.api.Test;
+
+public class MessageTest {
+
+ @Test
+ public void testMessageBuilderWithContext() {
+ String messageId = "wamid.HBgNNTUyNzk5NzAzMDkzNhUCABIYFDNBRjE2OTUyOTNCNTlCM0IzRDQ0AA==";
+ Context context = new Context();
+ context.setMessageId(messageId);
+
+ Message message = Message.MessageBuilder.builder()
+ .setTo("123456789")
+ .setContext(context)
+ .buildTextMessage(new TextMessage());
+
+ assertNotNull(message.getContext(), "Context should not be null");
+ assertEquals(messageId, message.getContext().getMessageId(), "Context field value mismatch");
+ }
+
+ @Test
+ public void testMessageWithoutContext() {
+ Message message = Message.MessageBuilder.builder()
+ .setTo("123456789")
+ .buildTextMessage(new TextMessage());
+
+ assertEquals(null, message.getContext(), "Context should be null");
+ }
+}