Skip to content

Commit 3366683

Browse files
committed
update java doc for text, media and template messages
1 parent ae8f64b commit 3366683

File tree

6 files changed

+189
-95
lines changed

6 files changed

+189
-95
lines changed

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/common-setting-java.md

Lines changed: 9 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,15 @@ ms.custom: include file
1111
ms.author: shamkh
1212
ms.custom: devx-track-extended-java, devx-track-js, devx-track-python
1313
zone_pivot_groups: acs-js-csharp-java-python
14-
---
14+
---
15+
16+
### Start sending messages between a business and a WhatsApp user
17+
18+
Conversations between a WhatsApp Business Account and a WhatsApp user can be initiated in one of two ways:
19+
- The business sends a template message to the WhatsApp user.
20+
- The WhatsApp user sends any message to the business number.
21+
22+
Regardless of how the conversation was started, **a business can only send template messages until the user sends a message to the business.** Only after the user sends a message to the business, the business is allowed to send text or media messages to the user during the active conversation. Once the 24 hour conversation window expires, the conversation must be reinitiated. To learn more about conversations, see the definition at [WhatsApp Business Platform](https://developers.facebook.com/docs/whatsapp/pricing#conversations).
1523

1624
### Authenticate the client
1725

@@ -137,60 +145,3 @@ Example:
137145
List<String> recipientList = new ArrayList<>();
138146
recipientList.add("+14255550199");
139147
```
140-
141-
### Start sending messages between a business and a WhatsApp user
142-
143-
Conversations between a WhatsApp Business Account and a WhatsApp user can be initiated in one of two ways:
144-
- The business sends a template message to the WhatsApp user.
145-
- The WhatsApp user sends any message to the business number.
146-
147-
Regardless of how the conversation was started, **a business can only send template messages until the user sends a message to the business.** Only after the user sends a message to the business, the business is allowed to send text or media messages to the user during the active conversation. Once the 24 hour conversation window expires, the conversation must be reinitiated. To learn more about conversations, see the definition at [WhatsApp Business Platform](https://developers.facebook.com/docs/whatsapp/pricing#conversations).
148-
149-
#### (Option 1) Initiate conversation from business - Send a template message
150-
Initiate a conversation by sending a template message.
151-
152-
First, create a MessageTemplate using the values for a template.
153-
> [!NOTE]
154-
> To check which templates you have available, see the instructions at [List templates](../../../../concepts/advanced-messaging/whatsapp/template-messages.md#list-templates).
155-
> If you don't have a template to use, proceed to [Option 2](#option-2-initiate-conversation-from-user).
156-
157-
Here's MessageTemplate creation using a default template, `sample_template`.
158-
If `sample_template` isn't available to you, skip to [Option 2](#option-2-initiate-conversation-from-user). For advanced users, see the page [Templates](../../../../concepts/advanced-messaging/whatsapp/template-messages.md) to understand how to send a different template with Option 1.
159-
160-
Messages SDK allows Contoso to send templated WhatsApp messages to WhatsApp users. To send template messages below details are required:
161-
- [WhatsApp Channel ID](#set-channel-registration-id)
162-
- [Recipient Phone Number in E16 format](#set-recipient-list)
163-
- Template details
164-
- Name like 'sample_template'
165-
- Language like 'en_us'
166-
- Parameters if any
167-
168-
```java
169-
// Assemble the template content
170-
String templateName = "sample_template";
171-
String templateLanguage = "en_us";
172-
MessageTemplate messageTemplate = new MessageTemplate(templateName, templateLanguage);
173-
174-
// Assemble template message
175-
TemplateNotificationContent templateContent = new TemplateNotificationContent(channelRegistrationId, recipientList, messageTemplate);
176-
177-
// Send template message
178-
SendMessageResult templateMessageResult = notificationClient.send(templateContent);
179-
180-
// Process result
181-
for (MessageReceipt messageReceipt : templateMessageResult.getReceipts()) {
182-
System.out.println("Message sent to:" + messageReceipt.getTo() + " and message id:" + messageReceipt.getMessageId());
183-
}
184-
```
185-
186-
Now, the user needs to respond to the template message. From the WhatsApp user account, reply to the template message received from the WhatsApp Business Account. The content of the message is irrelevant for this scenario.
187-
188-
> [!IMPORTANT]
189-
> The recipient must respond to the template message to initiate the conversation before text or media message can be delivered to the recipient.
190-
191-
#### (Option 2) Initiate conversation from user
192-
193-
The other option to initiate a conversation between a WhatsApp Business Account and a WhatsApp user is to have the user initiate the conversation.
194-
To do so, from your personal WhatsApp account, send a message to your business number (Sender ID).
195-
196-
:::image type="content" source="../media/get-started/user-initiated-conversation.png" lightbox="" alt-text="A WhatsApp conversation viewed on the web showing a user message sent to the WhatsApp Business Account number.":::

articles/communication-services/quickstarts/advanced-messaging/whatsapp/includes/get-started/messages-get-started-java.md

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -24,45 +24,20 @@ To set up an environment for sending messages, complete the steps in the followi
2424

2525
[!INCLUDE [Setting up for Java Application](../java-application-setup.md)]
2626

27-
## Object model
28-
29-
The following classes and interfaces handle some of the major features of the Azure Communication Services Advance Messaging SDK for Java.
30-
31-
| Class Name | Description |
32-
| --- |--- |
33-
| `NotificationMessagesClientBuilder` | Creates the Notification Messages Client. You provide it with an endpoint and a credential. |
34-
| `NotificationMessagesClient` | Needed to send WhatsApp messages and download media files. |
35-
| `NotificationMessagesAsyncClient` | Needed to send WhatsApp messages and download media files asynchronously. |
36-
| `SendMessageResult` | Contains the result from the Advance Messaging service for send notification message. |
37-
| `MessageTemplateClientBuilder` | Creates the Message Template Client. You provide it with an endpoint and a credential. |
38-
| `MessageTemplateClient` | Needed to get the list of WhatsApp templates. |
39-
| `MessageTemplateAsyncClient` | Needed to get the list of WhatsApp templates asynchronously. |
40-
41-
> [!NOTE]
42-
> For more information, see the Azure SDK for Java reference [com.azure.communication.messages](/java/api/com.azure.communication.messages)
43-
44-
## Common configuration
45-
46-
Complete these steps to add required code snippets to the `messages-quickstart.py` python program.
27+
## Code examples
4728

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).
4831
- [Authenticate the client](#authenticate-the-client).
4932
- [Set channel registration ID](#set-channel-registration-id).
5033
- [Set recipient list](#set-recipient-list).
51-
- [Start sending messages between a business and a WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
52-
53-
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting-java.md)]
54-
55-
## Code examples
56-
57-
Follow these steps to add required code snippets to the main function of your `App.java` file.
5834
- [Send a text message to a WhatsApp user](#send-a-text-message-to-a-whatsapp-user)
5935
- [Send an image media message to a WhatsApp user](#send-an-image-media-message-to-a-whatsapp-user)
6036
- [Send a document media message to a WhatsApp user](#send-a-document-media-message-to-a-whatsapp-user)
6137
- [Send an audio media message to a WhatsApp user](#send-an-audio-media-message-to-a-whatsapp-user)
6238
- [Send a video media message to a WhatsApp user](#send-a-video-media-message-to-a-whatsapp-user)
6339

64-
> [!IMPORTANT]
65-
> To send a text 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).
40+
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting-java.md)]
6641

6742
### Send a text message to a WhatsApp user
6843

@@ -73,6 +48,9 @@ Messages SDK allows Contoso to send text WhatsApp messages, which initiated What
7348

7449
In this example, we reply to the WhatsApp user with the text `"Thanks for your feedback.\n From Notification Messaging SDK."`
7550

51+
> [!IMPORTANT]
52+
> To send a text 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).
53+
7654
Assemble and send the text message:
7755

7856
```java
@@ -98,6 +76,9 @@ The Messages SDK enables Contoso to send media (image, video, audio, or document
9876
> [!IMPORTANT]
9977
> As of SDK version 1.1.0, `MediaNotificationContent` is being deprecated for images. We encourage you to use `ImageNotificationContent` to send images. Explore other content-specific classes for other media types like `DocumentNotificationContent`, `VideoNotificationContent`, and `AudioNotificationContent`.
10078
79+
> [!IMPORTANT]
80+
> To send a image 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).
81+
10182
Assemble and send the image message:
10283

10384
```java
@@ -121,6 +102,9 @@ The Messages SDK enables Contoso to send media (image, video, audio, or document
121102
- [Recipient Phone Number in E16 format](#set-recipient-list).
122103
- URL of the Video media.
123104

105+
> [!IMPORTANT]
106+
> To send a video 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).
107+
124108
Assemble and send the video message:
125109

126110
```java
@@ -144,6 +128,9 @@ The Messages SDK enables Contoso to send media (image, video, audio, or document
144128
- [Recipient Phone Number in E16 format](#set-recipient-list).
145129
- URL of the Audio media.
146130

131+
> [!IMPORTANT]
132+
> To send a audio 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).
133+
147134
Assemble and send the audio message:
148135

149136
```java
@@ -167,6 +154,9 @@ The Messages SDK enables Contoso to send media (image, video, audio, or document
167154
- [Recipient Phone Number in E16 format](#set-recipient-list).
168155
- URL of the Document media.
169156

157+
> [!IMPORTANT]
158+
> To send a document 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).
159+
170160
Assemble and send the document message:
171161

172162
```java
@@ -199,4 +189,4 @@ for (MessageReceipt messageReceipt : docMessageResult.getReceipts()) {
199189

200190
## Full sample code
201191

202-
Find the finalized code for this quickstart on [GitHub](https://github.com/Azure/azure-sdk-for-java/tree/d668cb44f64d303e71d2ee72a8b0382896aa09d5/sdk/communication/azure-communication-messages/src/samples/java/com/azure/communication/messages).
192+
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/java-application-setup.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ Open the `pom.xml` file in your text editor. Add the following dependency elemen
2929
<dependency>
3030
<groupId>com.azure</groupId>
3131
<artifactId>azure-communication-messages</artifactId>
32-
<version>1.0.0</version>
3332
</dependency>
3433
```
3534

@@ -53,3 +52,20 @@ public class App
5352
}
5453
}
5554
```
55+
56+
## Object model
57+
58+
The following classes and interfaces handle some of the major features of the Azure Communication Services Advance Messaging SDK for Java.
59+
60+
| Class Name | Description |
61+
| --- |--- |
62+
| `NotificationMessagesClientBuilder` | Creates the Notification Messages Client. You provide it with an endpoint and a credential. |
63+
| `NotificationMessagesClient` | Needed to send WhatsApp messages and download media files. |
64+
| `NotificationMessagesAsyncClient` | Needed to send WhatsApp messages and download media files asynchronously. |
65+
| `SendMessageResult` | Contains the result from the Advance Messaging service for send notification message. |
66+
| `MessageTemplateClientBuilder` | Creates the Message Template Client. You provide it with an endpoint and a credential. |
67+
| `MessageTemplateClient` | Needed to get the list of WhatsApp templates. |
68+
| `MessageTemplateAsyncClient` | Needed to get the list of WhatsApp templates asynchronously. |
69+
70+
> [!NOTE]
71+
> For more information, see the Azure SDK for Java reference [com.azure.communication.messages](https://learn.microsoft.com/en-us/java/api/overview/azure/communication-messages-readme?view=azure-java-stable)

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

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,68 @@ ms.author: shamkh
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 a Reaction messages to a WhatsApp user message](#send-a-reaction-messages-to-a-whatsapp-user-message).
35+
36+
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting-java.md)]
37+
38+
### Send a Reaction messages to a WhatsApp user message
39+
40+
The Messages SDK enables Contoso to send reaction WhatsApp messages, when initiated by WhatsApp users. To send text messages:
41+
- [WhatsApp Channel ID](#set-channel-registration-id).
42+
- [Recipient Phone Number in E16 format](#set-recipient-list).
43+
- Reaction message content.
44+
45+
> [!IMPORTANT]
46+
> 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).
47+
48+
Assemble and send the reaction to a message:
49+
50+
```java
51+
// Assemble reaction message
52+
String emoji = "\uD83D\uDE00";
53+
ReactionNotificationContent reaction = new ReactionNotificationContent("<CHANNEL_ID>", recipients, emoji, "<REPLY_MESSAGE_ID>");
54+
55+
// Send reaction to a message
56+
SendMessageResult textMessageResult = notificationClient.send(reaction);
57+
58+
// Process result
59+
for (MessageReceipt messageReceipt : textMessageResult.getReceipts()) {
60+
System.out.println("Message sent to:" + messageReceipt.getTo() + " and message id:" + messageReceipt.getMessageId());
61+
}
62+
```
63+
64+
### Run the code
65+
66+
1. Open to the directory that contains the `pom.xml` file and compile the project using the `mvn` command.
67+
68+
```console
69+
mvn compile
70+
```
71+
72+
1. Run the app by executing the following `mvn` command.
73+
74+
```console
75+
mvn exec:java -D"exec.mainClass"="com.communication.quickstart.App" -D"exec.cleanupDaemonThreads"="false"
76+
```
77+
78+
## Full sample code
79+
80+
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/stickers/messages-quickstart-sticker-messages-java.md

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,79 @@
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: 1/27/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 a Sticker messages to a WhatsApp user](#send-a-sticker-messages-to-a-whatsapp-user).
35+
36+
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting-java.md)]
37+
38+
### Send a sticker messages to a WhatsApp user
39+
40+
The Messages SDK enables Contoso to send reaction WhatsApp messages, when initiated by WhatsApp users. To send text messages:
41+
- [WhatsApp Channel ID](#set-channel-registration-id).
42+
- [Recipient Phone Number in E16 format](#set-recipient-list).
43+
- Sticker message content.
44+
45+
> [!IMPORTANT]
46+
> 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).
47+
48+
Assemble and send the sticker message:
49+
50+
```java
51+
// Assemble sticker message
52+
String stickerUrl = "https://www.gstatic.com/webp/gallery/1.sm.webp";
53+
StickerNotificationContent sticker = new StickerNotificationContent("<CHANNEL_ID>", recipients, stickerUrl);
54+
55+
// Send sticker message
56+
SendMessageResult textMessageResult = notificationClient.send(sticker);
57+
58+
// Process result
59+
for (MessageReceipt messageReceipt : textMessageResult.getReceipts()) {
60+
System.out.println("Message sent to:" + messageReceipt.getTo() + " and message id:" + messageReceipt.getMessageId());
61+
}
62+
```
63+
64+
### Run the code
65+
66+
1. Open to the directory that contains the `pom.xml` file and compile the project using the `mvn` command.
67+
68+
```console
69+
mvn compile
70+
```
71+
72+
1. Run the app by executing the following `mvn` command.
73+
74+
```console
75+
mvn exec:java -D"exec.mainClass"="com.communication.quickstart.App" -D"exec.cleanupDaemonThreads"="false"
76+
```
77+
78+
## Full sample code
79+
80+
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).

0 commit comments

Comments
 (0)