Skip to content

Commit eee6b1c

Browse files
authored
Merge pull request #1 from Shamkh/armohamed/interactive_js_java_doc
Java and JavaScript doc for interactive, sticker and reaction message
2 parents f335c21 + 8f75a45 commit eee6b1c

13 files changed

+849
-246
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/common-setting-javascript.md

Lines changed: 18 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ ms.custom: devx-track-extended-java, devx-track-js, devx-track-python
1313
zone_pivot_groups: acs-js-csharp-java-python
1414
---
1515

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).
23+
1624
### Authenticate the client
1725

1826
#### [Connection String](#tab/connection-string)
@@ -34,15 +42,15 @@ setx COMMUNICATION_SERVICES_CONNECTION_STRING "<your connection string>"
3442
For more information on how to set an environment variable for your system, follow the steps at [Store your connection string in an environment variable](../../../create-communication-resource.md#store-your-connection-string-in-an-environment-variable).
3543

3644

37-
To instantiate a MessageClient, add the following code to the `Main` method:
45+
To instantiate a NotificationClient, add the following code to the `Main` method:
3846
```javascript
39-
const MessageClient = require("@azure-rest/communication-messages").default;
47+
const NotificationClient = require("@azure-rest/communication-messages").default;
4048
4149
// Set Connection string
4250
const connectionString = process.env["COMMUNICATION_SERVICES_CONNECTION_STRING"];
4351
4452
// Instantiate the client
45-
const client = MessageClient(connectionString);
53+
const client = NotificationClient(connectionString);
4654
```
4755

4856
<a name='azure-active-directory'></a>
@@ -72,17 +80,17 @@ To create a `DefaultAzureCredential` object:
7280
npm install @azure/identity
7381
```
7482

75-
1. To instantiate a `MessageClient`, add the following code to the `Main` method.
83+
1. To instantiate a `NotificationClient`, add the following code to the `Main` method.
7684
```javascript
7785
const DefaultAzureCredential = require("@azure/identity").DefaultAzureCredential;
78-
const MessageClient = require("@azure-rest/communication-messages").default;
86+
const NotificationClient = require("@azure-rest/communication-messages").default;
7987
8088
// Configure authentication
8189
const endpoint = "https://<resource name>.communication.azure.com";
8290
let credential = new DefaultAzureCredential();
8391
8492
// Instantiate the client
85-
const client = MessageClient(endpoint, credential);
93+
const client = NotificationClient(endpoint, credential);
8694
```
8795

8896
#### [AzureKeyCredential](#tab/azurekeycredential)
@@ -102,17 +110,17 @@ After you add the environment variable, you might need to restart any running pr
102110

103111
For more information on how to set an environment variable for your system, follow the steps at [Store your connection string in an environment variable](../../../create-communication-resource.md#store-your-connection-string-in-an-environment-variable).
104112

105-
To instantiate a `MessageClient`, add the following code to the `Main` method:
113+
To instantiate a `NotificationClient`, add the following code to the `Main` method:
106114
```javascript
107115
const AzureKeyCredential = require("@azure/core-auth").AzureKeyCredential;
108-
const MessageClient = require("@azure-rest/communication-messages").default;
116+
const NotificationClient = require("@azure-rest/communication-messages").default;
109117
110118
// Configure authentication
111119
const endpoint = "https://<resource name>.communication.azure.com";
112120
const credential = new AzureKeyCredential("<your key credential>");
113121
114122
// Instantiate the client
115-
const client = MessageClient(endpoint, credential);
123+
const client = NotificationClient(endpoint, credential);
116124
```
117125

118126
---
@@ -149,81 +157,4 @@ Example:
149157
```javascript
150158
// Example only
151159
const recipientList = ["+14255550199"];
152-
```
153-
154-
### Start sending messages between a business and a WhatsApp user
155-
156-
Conversations between a WhatsApp Business Account and a WhatsApp user can be initiated in one of two ways:
157-
- The business sends a template message to the WhatsApp user.
158-
- The WhatsApp user sends any message to the business number.
159-
160-
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).
161-
162-
#### (Option 1) Initiate conversation from business - Send a template message
163-
Initiate a conversation by sending a template message.
164-
165-
First, create a MessageTemplate using the values for a template.
166-
> [!NOTE]
167-
> To check which templates you have available, see the instructions at [List templates](../../../../concepts/advanced-messaging/whatsapp/template-messages.md#list-templates).
168-
> If you don't have a template to use, proceed to [Option 2](#option-2-initiate-conversation-from-user).
169-
170-
Here's MessageTemplate creation using a default template, `sample_template`.
171-
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.
172-
173-
Messages SDK allows Contoso to send templated WhatsApp messages to WhatsApp users. To send template messages below details are required:
174-
- [WhatsApp Channel ID](#set-channel-registration-id)
175-
- [Recipient Phone Number in E16 format](#set-recipient-list)
176-
- Template details
177-
- Name like 'sample_template'
178-
- Language like 'en_us'
179-
- Parameters if any
180-
181-
```javascript
182-
// Assemble the template content
183-
const template = {
184-
name: "sample_template",
185-
language: "en_US"
186-
};
187-
```
188-
189-
For more examples of how to assemble your MessageTemplate and how to create your own template, refer to the following resource:
190-
- [Send WhatsApp Template Messages](../../../../concepts/advanced-messaging/whatsapp/template-messages.md)
191-
192-
For further WhatsApp requirements on templates, refer to the WhatsApp Business Platform API references:
193-
- [Create and Manage Templates](https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/)
194-
- [Template Components](https://developers.facebook.com/docs/whatsapp/business-management-api/message-templates/components)
195-
- [Sending Template Messages](https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates)
196-
197-
```javascript
198-
// Send template message
199-
const templateMessageResult = await client.path("/messages/notifications:send").post({
200-
contentType: "application/json",
201-
body: {
202-
channelRegistrationId: channelRegistrationId,
203-
to: recipientList,
204-
kind: "template",
205-
template: template
206-
}
207-
});
208-
209-
// Process result
210-
if (templateMessageResult.status === "202") {
211-
templateMessageResult.body.receipts.forEach((receipt) => {
212-
console.log("Message sent to:"+receipt.to+" with message id:"+receipt.messageId);
213-
});
214-
} else {
215-
throw new Error("Failed to send message");
216-
}
217-
```
218-
219-
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.
220-
221-
> [!IMPORTANT]
222-
> The recipient must respond to the template message to initiate the conversation before text or media message can be delivered to the recipient.
223-
224-
#### (Option 2) Initiate conversation from user
225-
226-
The other option to initiate a conversation between a WhatsApp Business Account and a WhatsApp user is to have the user initiate the conversation.
227-
To do so, from your personal WhatsApp account, send a message to your business number (Sender ID).
228-
229-
:::image type="content" source="../media/get-started/user-initiated-conversation.png" lightbox="../media/get-started/user-initiated-conversation.png" alt-text="A WhatsApp conversation viewed on the web showing a user message sent to the WhatsApp Business Account number.":::
160+
```

0 commit comments

Comments
 (0)