-
-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #74 from Bindambc/72-add-support-for-responding-to…
…-whatsapp-messages-with-reactions Added support for responding to messages with reactions (using emojis)
- Loading branch information
Showing
4 changed files
with
229 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/main/java/com/whatsapp/api/domain/messages/ReactionMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package com.whatsapp.api.domain.messages; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
/** | ||
* The type Reaction message. | ||
*/ | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public class ReactionMessage { | ||
@JsonProperty("message_id") | ||
private String messageId; | ||
@JsonProperty("emoji") | ||
private String emoji; | ||
|
||
/** | ||
* Instantiates a new Reaction message. | ||
* | ||
* @param messageId <b>required</b>. The WhatsApp Message ID (wamid) of the message on which the reaction should appear. The reaction will not be sent if: | ||
* <ul> | ||
* <li> | ||
* The message is older than 30 days | ||
* </li> | ||
* <li> | ||
* The message is a reaction message | ||
* </li> | ||
* <li>The message has been deleted</li> | ||
* </ul> | ||
* If the ID is of a message that has been deleted, the message will not be delivered. | ||
* @param emoji <b>required</b>. Emoji to appear on the message. | ||
* <ul> | ||
* <li>All emojis supported by Android and iOS devices are supported.</li> | ||
* <li>Rendered-emojis are supported.</li> | ||
* <li>If using emoji unicode values, values must be Java- or JavaScript-escape encoded.</li> | ||
* <li>Only one emoji can be sent in a reaction message</li> | ||
* <li>Use an empty string to remove a previously sent emoji.</li> | ||
* | ||
* </ul> | ||
*/ | ||
public ReactionMessage(String messageId, String emoji) { | ||
this.messageId = messageId; | ||
this.emoji = emoji; | ||
} | ||
|
||
/** | ||
* Instantiates a new Reaction message. | ||
*/ | ||
public ReactionMessage() { | ||
} | ||
|
||
/** | ||
* Gets message id. | ||
* | ||
* @return the message id | ||
*/ | ||
public String getMessageId() { | ||
return messageId; | ||
} | ||
|
||
/** | ||
* Sets message id. | ||
* | ||
* @param messageId <b>required</b>. The WhatsApp Message ID (wamid) of the message on which the reaction should appear. The reaction will not be sent if: | ||
* <ul> | ||
* <li> | ||
* The message is older than 30 days | ||
* </li> | ||
* <li> | ||
* The message is a reaction message | ||
* </li> | ||
* <li>The message has been deleted</li> | ||
* </ul> | ||
* If the ID is of a message that has been deleted, the message will not be delivered. | ||
* @return ReactionMessage | ||
*/ | ||
public ReactionMessage setMessageId(String messageId) { | ||
this.messageId = messageId; | ||
return this; | ||
} | ||
|
||
/** | ||
* Gets emoji. | ||
* | ||
* @return the emoji | ||
*/ | ||
public String getEmoji() { | ||
return emoji; | ||
} | ||
|
||
/** | ||
* Sets emoji. | ||
* | ||
* @param emoji <b>required</b>. Emoji to appear on the message. | ||
* <ul> | ||
* <li>All emojis supported by Android and iOS devices are supported.</li> | ||
* <li>Rendered-emojis are supported.</li> | ||
* <li>If using emoji unicode values, values must be Java- or JavaScript-escape encoded.</li> | ||
* <li>Only one emoji can be sent in a reaction message</li> | ||
* <li>Use an empty string to remove a previously sent emoji.</li> | ||
* | ||
* </ul> | ||
* @return ReactionMessage | ||
*/ | ||
public ReactionMessage setEmoji(String emoji) { | ||
this.emoji = emoji; | ||
return this; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/test/java/com/whatsapp/api/examples/SendIReactionMessageExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.whatsapp.api.examples; | ||
|
||
import com.whatsapp.api.WhatsappApiFactory; | ||
import com.whatsapp.api.domain.messages.Message.MessageBuilder; | ||
import com.whatsapp.api.domain.messages.ReactionMessage; | ||
import com.whatsapp.api.domain.messages.response.MessageResponse; | ||
import com.whatsapp.api.impl.WhatsappBusinessCloudApi; | ||
|
||
import static com.whatsapp.api.TestConstants.PHONE_NUMBER_1; | ||
import static com.whatsapp.api.TestConstants.PHONE_NUMBER_ID; | ||
import static com.whatsapp.api.TestConstants.TOKEN; | ||
|
||
|
||
public class SendIReactionMessageExample { | ||
|
||
public static void main(String[] args) { | ||
|
||
WhatsappApiFactory factory = WhatsappApiFactory.newInstance(TOKEN); | ||
|
||
WhatsappBusinessCloudApi whatsappBusinessCloudApi = factory.newBusinessCloudApi(); | ||
var emojiThumbsUp = "\uD83D\uDC4D"; | ||
var reactionMessage = new ReactionMessage()// | ||
.setMessageId("wamid.HBgNNTUyNzk5NzAzMDkzNhUCABIYFDNBRjE2OTUyOTNCNTlCM0IzRDQ0AA==")// | ||
.setEmoji(emojiThumbsUp);// | ||
|
||
var message = MessageBuilder.builder()// | ||
.setTo(PHONE_NUMBER_1)// | ||
.buildReactionMessage(reactionMessage); | ||
|
||
MessageResponse messageResponse = whatsappBusinessCloudApi.sendMessage(PHONE_NUMBER_ID, message); | ||
|
||
System.out.println(messageResponse); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters