Skip to content

Commit 8f75a45

Browse files
committed
added java doc for sticker, reaction & interactive message
1 parent 3366683 commit 8f75a45

File tree

6 files changed

+161
-13
lines changed

6 files changed

+161
-13
lines changed

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/interactive/messages-quickstart-interactive-messages-java.md

Lines changed: 150 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,163 @@
22
title: Include file
33
description: Include file
44
services: azure-communication-services
5-
author: shamkh
5+
author: arifibrahim4
66
ms.service: azure-communication-services
77
ms.subservice: advanced-messaging
8-
ms.date: 12/15/2024
8+
ms.date: 01/28/2025
99
ms.topic: include
1010
ms.custom: include file
11-
ms.author: shamkh
11+
ms.author: armohamed
1212
---
1313

1414
## Prerequisites
1515

16-
## Setting up
16+
- [WhatsApp Business Account registered with your Azure Communication Services resource](../../connect-whatsapp-business-account.md).
17+
- Active WhatsApp phone number to receive messages.
18+
- [Java Development Kit (JDK)](/java/azure/jdk/) version 8 or later.
19+
- [Apache Maven](https://maven.apache.org/download.cgi).
20+
21+
## Set up environment
22+
23+
To set up an environment for sending messages, complete the steps in the following sections.
1724

1825
[!INCLUDE [Setting up for Java Application](../java-application-setup.md)]
26+
27+
## Code examples
28+
29+
Follow these steps to add required code snippets to the main function of your `App.java` file.
30+
- [Start sending messages between a business and a WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
31+
- [Authenticate the client](#authenticate-the-client).
32+
- [Set channel registration ID](#set-channel-registration-id).
33+
- [Set recipient list](#set-recipient-list).
34+
- [Send an Interactive List options message to a WhatsApp user](#send-an-interactive-reply-button-message-to-a-whatsapp-user).
35+
- [Send an Interactive Reply Button message to a WhatsApp user](#send-an-interactive-reply-button-message-to-a-whatsapp-user).
36+
- [Send an Interactive Click-to-action Url based message to a WhatsApp user](#send-an-interactive-click-to-action-url-based-message-to-a-whatsapp-user)
37+
38+
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting-java.md)]
39+
40+
### Send an Interactive List options message to a WhatsApp user
41+
42+
The Messages SDK enables Contoso to send interactive WhatsApp messages, when initiated by a WhatsApp users. To send interactive messages:
43+
- [WhatsApp Channel ID](#set-channel-registration-id).
44+
- [Recipient Phone Number in E16 format](#set-recipient-list).
45+
- Interactive message to be sent.
46+
47+
> [!IMPORTANT]
48+
> To send a interactive message to a WhatsApp user, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
49+
50+
In this example, the business sends an interactive shipping options message to the user.
51+
52+
```java
53+
54+
// Create Express Shipping options group
55+
List<ActionGroupItem> group1 = new ArrayList<>();
56+
group1.add(new ActionGroupItem("priority_express", "Priority Mail Express", "Delivered on same day!"));
57+
group1.add(new ActionGroupItem("priority_mail", "Priority Mail", "Delivered in 1-2 days"));
58+
59+
// Create Normal Shipping options group
60+
List<ActionGroupItem> group2 = new ArrayList<>();
61+
group2.add(new ActionGroupItem("usps_ground_advantage", "USPS Ground Advantage", "Delivered in 2-5 days"));
62+
group2.add(new ActionGroupItem("normal_mail", "Normal Mail", "Delivered in 5-8 days"));
63+
64+
// Add Shipping options
65+
List<ActionGroup> options = new ArrayList<>();
66+
options.add(new ActionGroup("Express Delivery", group1));
67+
options.add(new ActionGroup("Normal Delivery", group2));
68+
ActionGroupContent actionGroupContent = new ActionGroupContent("Shipping Options", options);
69+
70+
// Build interactive message with body, header (optional), footer (optional)
71+
InteractiveMessage interactiveMessage = new InteractiveMessage(
72+
new TextMessageContent("Which shipping option do you want?"), new WhatsAppListActionBindings(actionGroupContent));
73+
interactiveMessage.setFooter(new TextMessageContent("Logistic Ltd"));
74+
interactiveMessage.setHeader(new TextMessageContent("Shipping Options"));
75+
76+
InteractiveNotificationContent interactiveMessageContent new InteractiveNotificationContent("<CHANNEL_ID>", recipients, interactiveMessage);
77+
78+
// Send a interactive message
79+
SendMessageResult textMessageResult = notificationClient.send(interactiveMessageContent);
80+
81+
// Process result
82+
for (MessageReceipt messageReceipt : textMessageResult.getReceipts()) {
83+
System.out.println("Message sent to:" + messageReceipt.getTo() + " and message id:" + messageReceipt.getMessageId());
84+
}
85+
```
86+
87+
### Send an Interactive Reply Button message to a WhatsApp user
88+
89+
The Messages SDK enables Contoso to send interactive WhatsApp messages, when initiated by a WhatsApp users. To send interactive messages:
90+
- [WhatsApp Channel ID](#set-channel-registration-id).
91+
- [Recipient Phone Number in E16 format](#set-recipient-list).
92+
- Interactive message to be sent.
93+
94+
> [!IMPORTANT]
95+
> To send a interactive message to a WhatsApp user, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
96+
97+
In this example, the business sends a interactive reply button message to the user.
98+
99+
```java
100+
// Assemble interactive reply button
101+
List<ButtonContent> buttonActions = new ArrayList<>();
102+
buttonActions.add(new ButtonContent("no", "No"));
103+
buttonActions.add(new ButtonContent("yes", "Yes"));
104+
ButtonSetContent buttonSet = new ButtonSetContent(buttonActions);
105+
InteractiveMessage interactiveMessage = new InteractiveMessage(new TextMessageContent("Do you want to proceed?"), new WhatsAppButtonActionBindings(buttonSet));
106+
107+
InteractiveNotificationContent interactiveMessageContent new InteractiveNotificationContent("<CHANNEL_ID>", recipients, interactiveMessage);
108+
109+
// Send a interactive message
110+
SendMessageResult textMessageResult = notificationClient.send(interactiveMessageContent);
111+
112+
// Process result
113+
for (MessageReceipt messageReceipt : textMessageResult.getReceipts()) {
114+
System.out.println("Message sent to:" + messageReceipt.getTo() + " and message id:" + messageReceipt.getMessageId());
115+
}
116+
```
117+
118+
### Send an Interactive Click-to-action Url based message to a WhatsApp user
119+
120+
The Messages SDK enables Contoso to send interactive WhatsApp messages, when initiated by a WhatsApp users. To send interactive messages:
121+
- [WhatsApp Channel ID](#set-channel-registration-id).
122+
- [Recipient Phone Number in E16 format](#set-recipient-list).
123+
- Interactive message to be sent.
124+
125+
> [!IMPORTANT]
126+
> To send a interactive message to a WhatsApp user, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
127+
128+
In this example, the business sends a click to a link message to the user.
129+
130+
```java
131+
LinkContent urlAction = new LinkContent("Click here to find out", "https://wallpapercave.com/wp/wp2163723.jpg");
132+
InteractiveMessage interactiveMessage = new InteractiveMessage(
133+
new TextMessageContent("The best Guardian of Galaxy"), new WhatsAppUrlActionBindings(urlAction));
134+
interactiveMessage.setFooter(new TextMessageContent("Intergalactic New Ltd"));
135+
136+
InteractiveNotificationContent interactiveMessageContent new InteractiveNotificationContent("<CHANNEL_ID>", recipients, interactiveMessage);
137+
138+
// Send a interactive message
139+
SendMessageResult textMessageResult = notificationClient.send(interactiveMessageContent);
140+
141+
// Process result
142+
for (MessageReceipt messageReceipt : textMessageResult.getReceipts()) {
143+
System.out.println("Message sent to:" + messageReceipt.getTo() + " and message id:" + messageReceipt.getMessageId());
144+
}
145+
```
146+
147+
148+
### Run the code
149+
150+
1. Open to the directory that contains the `pom.xml` file and compile the project using the `mvn` command.
151+
152+
```console
153+
mvn compile
154+
```
155+
156+
1. Run the app by executing the following `mvn` command.
157+
158+
```console
159+
mvn exec:java -D"exec.mainClass"="com.communication.quickstart.App" -D"exec.cleanupDaemonThreads"="false"
160+
```
161+
162+
## Full sample code
163+
164+
Find the finalized code for this quickstart on [GitHub](https://github.com/Azure/azure-sdk-for-java/tree/main/sdk/communication/azure-communication-messages/src/samples/java/com/azure/communication/messages).

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/interactive/messages-quickstart-interactive-messages-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ async function main() {
6565
const interactiveMessage = {
6666
body: {
6767
kind: "text",
68-
text: "Do you want to proceed?",
68+
text: "Which shipping option do you want?",
6969
},
7070
action: {
7171
kind: "whatsAppListAction",

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/reactions/messages-quickstart-reaction-messages-java.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
title: Include file
33
description: Include file
44
services: azure-communication-services
5-
author: shamkh
5+
author: arifibrahim4
66
ms.service: azure-communication-services
77
ms.subservice: advanced-messaging
8-
ms.date: 12/15/2024
8+
ms.date: 01/28/2025
99
ms.topic: include
1010
ms.custom: include file
11-
ms.author: shamkh
11+
ms.author: armohamed
1212
---
1313

1414
## Prerequisites
@@ -40,15 +40,16 @@ Follow these steps to add required code snippets to the main function of your `A
4040
The Messages SDK enables Contoso to send reaction WhatsApp messages, when initiated by WhatsApp users. To send text messages:
4141
- [WhatsApp Channel ID](#set-channel-registration-id).
4242
- [Recipient Phone Number in E16 format](#set-recipient-list).
43-
- Reaction message content.
43+
- Unicode escape sequence of the emoji.
44+
- Message Id of message you want to apply the emoji to.
4445

4546
> [!IMPORTANT]
4647
> To send a reaction to user message, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
4748
4849
Assemble and send the reaction to a message:
4950

5051
```java
51-
// Assemble reaction message
52+
// Assemble reaction to a message
5253
String emoji = "\uD83D\uDE00";
5354
ReactionNotificationContent reaction = new ReactionNotificationContent("<CHANNEL_ID>", recipients, emoji, "<REPLY_MESSAGE_ID>");
5455

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/reactions/messages-quickstart-reaction-messages-javascript.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ Follow these steps to add required code snippets to your `send-messages.js` file
3737
The Messages SDK enables Contoso to send reaction WhatsApp messages, when initiated by WhatsApp users. To send text messages:
3838
- [WhatsApp Channel ID](#set-channel-registration-id).
3939
- [Recipient Phone Number in E16 format](#set-recipient-list).
40-
- Reaction message content.
40+
- Emoji.
41+
- Message Id of message you want to apply the emoji to.
4142

4243
> [!IMPORTANT]
4344
> To send a reaction to user message, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/stickers/messages-quickstart-sticker-messages-java.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Follow these steps to add required code snippets to the main function of your `A
4040
The Messages SDK enables Contoso to send reaction WhatsApp messages, when initiated by WhatsApp users. To send text messages:
4141
- [WhatsApp Channel ID](#set-channel-registration-id).
4242
- [Recipient Phone Number in E16 format](#set-recipient-list).
43-
- Sticker message content.
43+
- URL of a sticker.
4444

4545
> [!IMPORTANT]
4646
> To send a sticker message to user, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/stickers/messages-quickstart-sticker-messages-javascript.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Follow these steps to add required code snippets to your `send-messages.js` file
3737
The Messages SDK enables Contoso to send reaction WhatsApp messages, when initiated by WhatsApp users. To send text messages:
3838
- [WhatsApp Channel ID](#set-channel-registration-id).
3939
- [Recipient Phone Number in E16 format](#set-recipient-list).
40-
- Sticker message content.
40+
- URL of a sticker.
4141

4242
> [!IMPORTANT]
4343
> To send a sticker message to user, the WhatsApp user must first send a message to the WhatsApp Business Account. For more information, see [Start sending messages between business and WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).

0 commit comments

Comments
 (0)