Skip to content

Commit ae8f64b

Browse files
committed
javascript doc update and cleanup
1 parent 3574b44 commit ae8f64b

File tree

6 files changed

+77
-139
lines changed

6 files changed

+77
-139
lines changed

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+
```

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

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,50 +16,28 @@ ms.author: armohamed
1616
- [WhatsApp Business Account registered with your Azure Communication Services resource](../../connect-whatsapp-business-account.md).
1717
- Active WhatsApp phone number to receive messages.
1818
- [Node.js](https://nodejs.org/) Active LTS and Maintenance LTS versions (We recommend 8.11.1 and 10.14.1).
19-
- In a terminal or command window, make sure Node.js is installed.
19+
- [Node.js](https://nodejs.org/) Active LTS and Maintenance LTS versions (8.11.1 and 10.14.1 are recommended)
20+
- In a terminal or command window, run `node --version` to check that Node.js is installed
2021

21-
```console
22-
node --version
23-
```
24-
25-
## Set up the environment
26-
27-
To set up an environment for sending messages, complete the steps in the following sections.
22+
## Setting up
2823

2924
[!INCLUDE [Setting up for JavaScript Application](../javascript-application-setup.md)]
3025

31-
## Object model
32-
33-
The following classes and interfaces handle some of the major features of the Azure Communication Services Advance Messaging SDK for JavaScript.
34-
35-
| Class Name | Description |
36-
| --- | --- |
37-
| `MessageClient` | Connects to your Azure Communication Services resource. It sends the messages. |
38-
| `MessageTemplate` | Defines which template you use and the content of the template properties for your message. |
39-
40-
> [!NOTE]
41-
> For more information, see the Azure SDK for JavaScript reference [@azure-rest/communication-messages package](/javascript/api/@azure-rest/communication-messages)
42-
43-
## Common configuration
44-
45-
Follow these steps to add required code snippets to the `messages-quickstart.py` python program.
26+
## Code examples
4627

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

39+
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting-javascript.md)]
40+
6341
> [!IMPORTANT]
6442
> To send a 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).
6543
@@ -251,4 +229,4 @@ node ./send-messages.js
251229

252230
## Full sample code
253231

254-
You can download the sample app from [GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest/samples).
232+
Find the finalized code for this quickstart on [GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest/samples).

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,28 @@ ms.custom: include file
1111
ms.author: armohamed
1212
---
1313

14-
## Set up environment
14+
## Prerequisites
15+
- [WhatsApp Business Account registered with your Azure Communication Services resource](../../connect-whatsapp-business-account.md).
16+
- Active WhatsApp phone number to receive messages.
17+
- [Node.js](https://nodejs.org/) Active LTS and Maintenance LTS versions (8.11.1 and 10.14.1 are recommended)
18+
- In a terminal or command window, run `node --version` to check that Node.js is installed
1519

16-
To set up an environment for sending messages, complete the steps in the following sections.
20+
## Setting up
1721

1822
[!INCLUDE [Setting up for JavaScript Application](../javascript-application-setup.md)]
1923

2024
## Code examples
2125

2226
Follow these steps to add required code snippets to your `send-messages.js` file.
27+
- [Start sending messages between a business and a WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
28+
- [Authenticate the client](#authenticate-the-client).
29+
- [Set channel registration ID](#set-channel-registration-id).
30+
- [Set recipient list](#set-recipient-list).
2331
- [Send an Interactive List options message to a WhatsApp user](#send-an-interactive-reply-button-message-to-a-whatsapp-user).
2432
- [Send an Interactive Reply Button message to a WhatsApp user](#send-an-interactive-reply-button-message-to-a-whatsapp-user).
2533
- [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)
2634

35+
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting-javascript.md)]
2736

2837
### Send an Interactive List options message to a WhatsApp user
2938

@@ -293,4 +302,4 @@ node ./send-messages.js
293302

294303
## Full sample code
295304

296-
Find the finalized code for this quickstart on [GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest/samples).
305+
Find the finalized code for this sample on [GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest/samples).

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ ms.author: armohamed
1212
---
1313

1414
## Prerequisites
15+
- [WhatsApp Business Account registered with your Azure Communication Services resource](../../connect-whatsapp-business-account.md).
16+
- Active WhatsApp phone number to receive messages.
17+
- [Node.js](https://nodejs.org/) Active LTS and Maintenance LTS versions (8.11.1 and 10.14.1 are recommended)
18+
- In a terminal or command window, run `node --version` to check that Node.js is installed
1519

1620
## Setting up
1721

@@ -20,8 +24,14 @@ ms.author: armohamed
2024
## Code examples
2125

2226
Follow these steps to add required code snippets to your `send-messages.js` file.
27+
- [Start sending messages between a business and a WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
28+
- [Authenticate the client](#authenticate-the-client).
29+
- [Set channel registration ID](#set-channel-registration-id).
30+
- [Set recipient list](#set-recipient-list).
2331
- [Send a Reaction messages to a WhatsApp user message](#send-a-reaction-messages-to-a-whatsapp-user-message).
2432

33+
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting-javascript.md)]
34+
2535
### Send a Reaction messages to a WhatsApp user message
2636

2737
The Messages SDK enables Contoso to send reaction WhatsApp messages, when initiated by WhatsApp users. To send text messages:
@@ -88,4 +98,4 @@ node ./send-messages.js
8898

8999
## Full sample code
90100

91-
Find the finalized code for this quickstart on [GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest/samples).
101+
Find the finalized code for this sample on [GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest/samples).

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ ms.author: armohamed
1212
---
1313

1414
## Prerequisites
15+
- [WhatsApp Business Account registered with your Azure Communication Services resource](../../connect-whatsapp-business-account.md).
16+
- Active WhatsApp phone number to receive messages.
17+
- [Node.js](https://nodejs.org/) Active LTS and Maintenance LTS versions (8.11.1 and 10.14.1 are recommended)
18+
- In a terminal or command window, run `node --version` to check that Node.js is installed
1519

1620
## Setting up
1721

@@ -20,8 +24,14 @@ ms.author: armohamed
2024
## Code examples
2125

2226
Follow these steps to add required code snippets to your `send-messages.js` file.
27+
- [Start sending messages between a business and a WhatsApp user](#start-sending-messages-between-a-business-and-a-whatsapp-user).
28+
- [Authenticate the client](#authenticate-the-client).
29+
- [Set channel registration ID](#set-channel-registration-id).
30+
- [Set recipient list](#set-recipient-list).
2331
- [Send a Sticker messages to a WhatsApp user](#send-a-sticker-messages-to-a-whatsapp-user).
2432

33+
[!INCLUDE [Common setting for using Advanced Messages SDK](../common-setting-javascript.md)]
34+
2535
### Send a sticker messages to a WhatsApp user
2636

2737
The Messages SDK enables Contoso to send reaction WhatsApp messages, when initiated by WhatsApp users. To send text messages:
@@ -87,4 +97,4 @@ node ./send-messages.js
8797

8898
## Full sample code
8999

90-
Find the finalized code for this quickstart on [GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest/samples).
100+
Find the finalized code for this sample on [GitHub](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/communication/communication-messages-rest/samples).

0 commit comments

Comments
 (0)