Skip to content

Commit 5559b3c

Browse files
authored
Java and JS doc fixes (#14)
* review comment fixes
1 parent b837076 commit 5559b3c

File tree

2 files changed

+44
-53
lines changed

2 files changed

+44
-53
lines changed

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

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ To set up an environment for sending messages, take the steps in the following s
2727
Open your terminal or command window and navigate to the directory where you would like to create your Java application. Run the following command to generate the Java project from the maven-archetype-quickstart template.
2828

2929
```console
30-
mvn archetype:generate -DgroupId=com.communication.quickstart -DartifactId=communication-quickstart -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
30+
mvn archetype:generate -DgroupId="com.communication.quickstart" -DartifactId="communication-quickstart" -DarchetypeArtifactId="maven-archetype-quickstart" -DarchetypeVersion="1.4" -DinteractiveMode="false"
3131
```
3232

3333
The `generate` goal creates a directory with the same name as the `artifactId` value. Under this directory, the **src/main/java** directory contains the project source code, the **src/test/java directory** contains the test source, and the **pom.xml** file is the project's Project Object Model (POM).
@@ -51,14 +51,8 @@ Open **/src/main/java/com/communication/quickstart/App.java** in a text editor,
5151
```java
5252
package com.communication.quickstart;
5353

54+
import com.azure.communication.messages.*;
5455
import com.azure.communication.messages.models.*;
55-
import com.azure.communication.messages.models.channels.WhatsAppMessageButtonSubType;
56-
import com.azure.communication.messages.models.channels.WhatsAppMessageTemplateBindings;
57-
import com.azure.communication.messages.models.channels.WhatsAppMessageTemplateBindingsButton;
58-
import com.azure.communication.messages.models.channels.WhatsAppMessageTemplateBindingsComponent;
59-
import com.azure.core.credential.AzureKeyCredential;
60-
import com.azure.core.credential.TokenCredential;
61-
import com.azure.identity.DefaultAzureCredentialBuilder;
6256

6357
import java.util.ArrayList;
6458
import java.util.List;
@@ -169,14 +163,21 @@ To create a `DefaultAzureCredential` object:
169163

170164
NotificationMessage or MessageTemplate clients can also be created and authenticated using the endpoint and Azure Key Credential acquired from an Azure Communication Resource in the [Azure portal](https://portal.azure.com/).
171165

172-
```java
173-
String endpoint = "https://<resource name>.communication.azure.com";
174-
AzureKeyCredential azureKeyCredential = new AzureKeyCredential("<access key>");
175-
NotificationMessagesClient notificationClient = new NotificationMessagesClientBuilder()
176-
.endpoint(endpoint)
177-
.credential(azureKeyCredential)
178-
.buildClient();
179-
```
166+
1. Add the import
167+
```java
168+
import com.azure.core.credential.AzureKeyCredential;
169+
```
170+
171+
1. To instantiate a `NotificationMessagesClient`, add the following code to the `Main` method.
172+
173+
```java
174+
String endpoint = "https://<resource name>.communication.azure.com";
175+
AzureKeyCredential azureKeyCredential = new AzureKeyCredential("<access key>");
176+
NotificationMessagesClient notificationClient = new NotificationMessagesClientBuilder()
177+
.endpoint(endpoint)
178+
.credential(azureKeyCredential)
179+
.buildClient();
180+
```
180181

181182
---
182183

@@ -244,10 +245,12 @@ MessageTemplate messageTemplate = new MessageTemplate(templateName, templateLang
244245
TemplateNotificationContent templateContent = new TemplateNotificationContent(channelRegistrationId, recipientList, messageTemplate);
245246

246247
// Send template message
247-
SendMessageResult result = notificationClient.send(templateContent);
248+
SendMessageResult templateMessageResult = notificationClient.send(templateContent);
248249

249250
// Process result
250-
result.getReceipts().forEach(r -> System.out.println("Message sent to:"+r.getTo() + " and message id:"+ r.getMessageId()));
251+
for (MessageReceipt messageReceipt : templateMessageResult.getReceipts()) {
252+
System.out.println("Message sent to:" + messageReceipt.getTo() + " and message id:" + messageReceipt.getMessageId());
253+
}
251254
```
252255

253256
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.
@@ -275,10 +278,12 @@ Assemble then send the text message:
275278
TextNotificationContent textContent = new TextNotificationContent(channelRegistrationId, recipientList, "“Thanks for your feedback.");
276279

277280
// Send text message
278-
SendMessageResult result = notificationClient.send(textContent);
281+
SendMessageResult textMessageResult = notificationClient.send(textContent);
279282

280283
// Process result
281-
result.getReceipts().forEach(r -> System.out.println("Message sent to:"+r.getTo() + " and message id:"+ r.getMessageId()));
284+
for (MessageReceipt messageReceipt : textMessageResult.getReceipts()) {
285+
System.out.println("Message sent to:" + messageReceipt.getTo() + " and message id:" + messageReceipt.getMessageId());
286+
}
282287
```
283288

284289
### Send a media message to a WhatsApp user
@@ -298,10 +303,12 @@ Assemble then send the media message:
298303
MediaNotificationContent mediaContent = new MediaNotificationContent(channelRegistrationId, recipientList, mediaUrl);
299304

300305
// Send media message
301-
SendMessageResult result = notificationClient.send(mediaContent);
306+
SendMessageResult mediaMessageResult = notificationClient.send(mediaContent);
302307

303308
// Process result
304-
result.getReceipts().forEach(r -> System.out.println("Message sent to:"+r.getTo() + " and message id:"+ r.getMessageId()));
309+
for (MessageReceipt messageReceipt : mediaMessageResult.getReceipts()) {
310+
System.out.println("Message sent to:" + messageReceipt.getTo() + " and message id:" + messageReceipt.getMessageId());
311+
}
305312
```
306313

307314
## Run the code
@@ -312,12 +319,6 @@ result.getReceipts().forEach(r -> System.out.println("Message sent to:"+r.getTo(
312319
mvn compile
313320
```
314321

315-
1. Build the package.
316-
317-
```console
318-
mvn package
319-
```
320-
321322
1. Run the app by executing the following `mvn` command.
322323

323324
```console

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

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,12 @@ setx COMMUNICATION_SERVICES_CONNECTION_STRING "<your connection string>"
102102

103103
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).
104104

105-
Use the `npm install` command to install the dotenv package.
106-
107-
```console
108-
npm install dotenv --save
109-
```
110105

111106
To instantiate a MessageClient, add the following code to the `Main` method:
112107
```javascript
113108
const MessageClient = require("@azure-rest/communication-messages").default;
114109

115-
// Load the .env file if it exists
116-
import * as dotenv from "dotenv";
117-
dotenv.config();
118-
119-
// Configure authentication by retrieving the environment variable
110+
// Set Connection string
120111
const connectionString = process.env["COMMUNICATION_SERVICES_CONNECTION_STRING"];
121112

122113
// Instantiate the client
@@ -224,7 +215,7 @@ const recipientList = ["<to WhatsApp phone number>"];
224215
```
225216

226217
Example:
227-
```csharp
218+
```javascript
228219
// Example only
229220
const recipientList = ["+14255550199"];
230221
```
@@ -265,7 +256,7 @@ For further WhatsApp requirements on templates, refer to the WhatsApp Business P
265256

266257
```javascript
267258
// Send template message
268-
const result = await client.path("/messages/notifications:send").post({
259+
const templateMessageResult = await client.path("/messages/notifications:send").post({
269260
contentType: "application/json",
270261
body: {
271262
channelRegistrationId: channelRegistrationId,
@@ -276,8 +267,8 @@ const result = await client.path("/messages/notifications:send").post({
276267
});
277268

278269
// Process result
279-
if (result.status === "202") {
280-
result.body.receipts.forEach((receipt) => {
270+
if (templateMessageResult.status === "202") {
271+
templateMessageResult.body.receipts.forEach((receipt) => {
281272
console.log("Message sent to:"+receipt.to+" with message id:"+receipt.messageId);
282273
});
283274
} else {
@@ -307,7 +298,7 @@ In the text message, provide text to send to the recipient. In this example, we
307298
Assemble and send the media message:
308299
```javascript
309300
// Send text message
310-
const result = await client.path("/messages/notifications:send").post({
301+
const textMessageResult = await client.path("/messages/notifications:send").post({
311302
contentType: "application/json",
312303
body: {
313304
channelRegistrationId: channelRegistrationId,
@@ -318,8 +309,8 @@ const result = await client.path("/messages/notifications:send").post({
318309
});
319310

320311
// Process result
321-
if (result.status === "202") {
322-
result.body.receipts.forEach((receipt) => {
312+
if (textMessageResult.status === "202") {
313+
textMessageResult.body.receipts.forEach((receipt) => {
323314
console.log("Message sent to:"+receipt.to+" with message id:"+receipt.messageId);
324315
});
325316
} else {
@@ -332,28 +323,27 @@ if (result.status === "202") {
332323
> [!IMPORTANT]
333324
> 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).
334325
335-
To send a media message, provide a URI to an image.
336-
As an example, create a URI:
337-
```csharp
338-
var uri = new Uri("https://aka.ms/acsicon1");
326+
To send a media message, provide a URL to an image. As an example,
327+
```javascript
328+
const url = "https://aka.ms/acsicon1";
339329
```
340330

341331
Assemble and send the media message:
342332
```javascript
343333
// Send media message
344-
const result = await client.path("/messages/notifications:send").post({
334+
const mediaMessageResult = await client.path("/messages/notifications:send").post({
345335
contentType: "application/json",
346336
body: {
347337
channelRegistrationId: channelRegistrationId,
348338
to: recipientList,
349339
kind: "image",
350-
mediaUri: uri
340+
mediaUri: url
351341
}
352342
});
353343

354344
// Process result
355-
if (result.status === "202") {
356-
result.body.receipts.forEach((receipt) => {
345+
if (mediaMessageResult.status === "202") {
346+
mediaMessageResult.body.receipts.forEach((receipt) => {
357347
console.log("Message sent to:"+receipt.to+" with message id:"+receipt.messageId);
358348
});
359349
} else {

0 commit comments

Comments
 (0)