Skip to content

Commit c77a6f3

Browse files
authored
Review, edite, raised Acrolinx from 82 to 100
1 parent b69b651 commit c77a6f3

File tree

1 file changed

+66
-37
lines changed

1 file changed

+66
-37
lines changed

articles/communication-services/tutorials/includes/twilio-to-acs-chat-js-tutorial.md

Lines changed: 66 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
title: include file
3-
description: include file
2+
title: Migrating from Twilio Conversations Chat to Azure Communication Services Chat JavaScript
3+
description: Guide describes how to migrate JavaScript apps from Twilio Conversations Chat to Azure Communication Services Chat SDK.
44
services: azure-communication-services
55
ms.date: 07/22/2024
66
ms.topic: include
@@ -16,8 +16,9 @@ ms.custom: mode-other
1616
1. **Azure Account:** Make sure that your Azure account is active. New users can create a free account at [Microsoft Azure](https://azure.microsoft.com/free/).
1717
2. **Node.js 18:** Ensure Node.js 18 is installed on your system. Download from [Node.js](https://nodejs.org/en).
1818
3. **Communication Services Resource:** Set up a [Communication Services Resource](../../quickstarts/create-communication-resource.md?tabs=windows&pivots=platform-azp) via your Azure portal and note your connection string.
19-
4. **Azure CLI:** Follow the instructions to [Install Azure CLI on Windows](/cli/azure/install-azure-cli-windows?tabs=azure-cli)..
19+
4. **Azure CLI:** Follow the instructions to [Install Azure CLI on Windows](/cli/azure/install-azure-cli-windows?tabs=azure-cli).
2020
5. **User Access Token:** Generate a user access token to instantiate the chat client. You can create one using the Azure CLI as follows:
21+
2122
```console
2223
az communication identity token issue --scope voip --connection-string "yourConnectionString"
2324
```
@@ -41,21 +42,24 @@ The `--save` option adds the library as a dependency in your **package.json** fi
4142
### Remove the Twilio SDK from the project
4243

4344
You can remove the Twilio SDK from your project by uninstalling the package.
45+
4446
```console
4547
npm uninstall twilio-conversations
4648
```
4749

4850
## Object model
51+
4952
The following classes and interfaces handle some of the major features of the Azure Communication Services Chat SDK for JavaScript.
5053

5154
| Name | Description |
5255
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
53-
| ChatClient | This class is needed for the Chat functionality. You instantiate it with your subscription information, and use it to create, get, delete threads, and subscribe to chat events. |
54-
| ChatThreadClient | This class is needed for the Chat Thread functionality. You obtain an instance via the ChatClient, and use it to send/receive/update/delete messages, add/remove/get users, send typing notifications and read receipts. |
56+
| `ChatClient` | This class is needed for the Chat function. Instantiate it with your subscription information, and use it to create, get, delete threads, and subscribe to chat events. |
57+
| `ChatThreadClient` | This class is needed for the Chat Thread function. Get an instance via the `ChatClient`, and use it to send/receive/update/delete messages, add/remove/get users, send typing notifications, and read receipts. |
5558

5659
### Initialize the Chat Client
5760

5861
#### Twilio
62+
5963
```JavaScript
6064
/* Initialization */
6165
import { Client } from '@twilio/conversations';
@@ -74,7 +78,8 @@ client.on('stateChanged', (state) => {
7478
});
7579
```
7680
#### Azure Communication Services
77-
Similar to Twilio, the first step is to get an **access token** as well as the Communication Service **endpoint** that was generated as part of the prerequisite steps. Replace those in the code.
81+
82+
Similar to Twilio, the first step is to get an **access token** and the Communication Service **endpoint** that was generated as part of the prerequisite steps. Replace the placeholders in the code.
7883

7984
```JavaScript
8085
import { ChatClient } from '@azure/communication-chat';
@@ -92,7 +97,8 @@ console.log('Azure Communication Chat client created!');
9297
### Start a chat thread
9398

9499
#### Twilio
95-
This is how you start a chat thread in Twilio Conversations. Use `FriendlyName` to give a human-readable name to this conversation.
100+
101+
Start a chat thread in Twilio Conversations. Use `FriendlyName` to give a human-readable name to this conversation.
96102

97103
```JavaScript
98104
let conversation = await client.createConversation({
@@ -102,14 +108,15 @@ await conversation.join();
102108
```
103109

104110
#### Azure Communication Services
111+
105112
Use the `createThread` method to create a chat thread.
106113

107-
`createThreadRequest` is used to describe the thread request:
114+
Use `createThreadRequest` to describe the thread request:
108115

109-
- Use `topic` to give a topic to this chat. Topics can be updated after the chat thread is created using the `UpdateThread` function.
116+
- Use `topic` to give a topic to this chat. update `topic` after you create the chat thread using the `UpdateThread` function.
110117
- Use `participants` to list the participants to be added to the chat thread.
111118

112-
When resolved, `createChatThread` method returns a `CreateChatThreadResult`. This model contains a `chatThread` property where you can access the `id` of the newly created thread. You can then use the `id` to get an instance of a `ChatThreadClient`. The `ChatThreadClient` can then be used to perform operation within the thread such as sending messages or listing participants.
119+
When resolved, `createChatThread` method returns a `CreateChatThreadResult`. This model contains a `chatThread` property where you can access the `id` of the newly created thread. Then use the `id` to get an instance of a `ChatThreadClient`. Then use the `ChatThreadClient` to perform operation within the thread such as sending messages or listing participants.
113120

114121
```JavaScript
115122
async function createChatThread() {
@@ -136,7 +143,9 @@ async function createChatThread() {
136143
### Get a chat thread client
137144

138145
#### Twilio
139-
This is how you get a chat thread (conversation) in Twilio.
146+
147+
Get a chat thread (conversation) in Twilio.
148+
140149
```JavaScript
141150
if (selectedConversation) {
142151
conversationContent = (
@@ -151,24 +160,30 @@ if (selectedConversation) {
151160
conversationContent = "";
152161
}
153162
```
163+
154164
#### Azure Communication Services
155-
The `getChatThreadClient` method returns a `chatThreadClient` for a thread that already exists. It can be used for performing operations on the created thread: add participants, send message, etc. threadId is the unique ID of the existing chat thread.
165+
166+
The `getChatThreadClient` method returns a `chatThreadClient` for a thread that already exists. Use it to perform operations on the created thread: add participants, send message, and so on. The `threadId` is the unique ID of the existing chat thread.
156167

157168
```JavaScript
158169
let chatThreadClient = chatClient.getChatThreadClient(threadId);
159170
console.log(`Chat Thread client for threadId:${threadId}`);
160-
161171
```
162-
Add this code in place of the `<CREATE CHAT THREAD CLIENT>` comment in **client.js**, refresh your browser tab and check the console, you should see:
172+
173+
Add this code in place of the `<CREATE CHAT THREAD CLIENT>` comment in **client.js**, refresh your browser tab, and check the console. You should see:
174+
163175
```console
164176
Chat Thread client for threadId: <threadId>
165177
```
166178

167179
### Add a user as a participant to the chat thread
168-
Once a chat thread is created, you can then add and remove users from it. By adding users, you give them access to send messages to the chat thread and add/remove other participants.
180+
181+
Once you create a chat thread, you can then add and remove users from it. By adding users, you give them access to send messages to the chat thread and add/remove other participants.
169182

170183
#### Twilio
171-
This is how you add a participant to a chat thread.
184+
185+
Add a participant to a chat thread.
186+
172187
```JavaScript
173188
// add chat participant to the conversation by its identity
174189
await conversation.add('identity');
@@ -183,9 +198,10 @@ conversation.on('participantJoined', (participant) => {
183198
```
184199

185200
#### Azure Communication Services
186-
Before calling the `addParticipants` method, ensure that you've acquired a new access token and identity for that user. The user will need that access token in order to initialize their chat client.
187201

188-
`addParticipantsRequest` describes the request object wherein `participants` lists the participants to be added to the chat thread;
202+
Before calling the `addParticipants` method, be sure to acquire a new access token and identity for that user. The user needs that access token to initialize their chat client.
203+
204+
`addParticipantsRequest` describes the request object wherein `participants` lists the participants to be added to the chat thread:
189205
- `id`, required, is the communication identifier to be added to the chat thread.
190206
- `displayName`, optional, is the display name for the thread participant.
191207
- `shareHistoryTime`, optional, is the time from which the chat history is shared with the participant. To share history since the inception of the chat thread, set this property to any date equal to, or less than the thread creation time. To share no history previous to when the participant was added, set it to the current date. To share partial history, set it to the date of your choice.
@@ -205,13 +221,16 @@ const addParticipantsRequest =
205221
await chatThreadClient.addParticipants(addParticipantsRequest);
206222

207223
```
208-
Replace **NEW_PARTICIPANT_USER_ID** with a [new user ID](../../identity/access-tokens.md)
224+
Replace **NEW_PARTICIPANT_USER_ID** with a [new user ID](../../quickstarts/identity/access-tokens.md)
209225

210226
### Send a message to a chat thread
211-
Unlike Twilio, ACS does not have separate functions for sending text messages or media.
227+
228+
Unlike Twilio, Azure Communication Services doesn't have separate functions for sending text messages or media.
212229

213230
#### Twilio
214-
This is how you send a text message in Twilio.
231+
232+
To send a text message in Twilio.
233+
215234
```JavaScript
216235
// Send Text Message
217236
await conversation
@@ -222,7 +241,9 @@ await conversation
222241
.send();
223242

224243
```
225-
This is how you send media in Twilio.
244+
245+
To send media in Twilio.
246+
226247
```JavaScript
227248
const file =
228249
await fetch("https://v.fastcdn.co/u/ed1a9b17/52533501-0-logo.svg");
@@ -242,20 +263,22 @@ await conversation
242263
```
243264

244265
#### Azure Communication Services
266+
245267
Use `sendMessage` method to send a message to a thread identified by threadId.
246268

247269
`sendMessageRequest` is used to describe the message request:
248270

249-
- Use `content` to provide the chat message content;
271+
- Use `content` to provide the chat message content.
250272

251-
`sendMessageOptions` is used to describe the operation optional params:
273+
Use `sendMessageOptions` to describe the operation optional params:
252274

253-
- Use `senderDisplayName` to specify the display name of the sender;
254-
- Use `type` to specify the message type, such as 'text' or 'html';
255-
This is how you accomplish the "Media" property in Twilio.
256-
- Use `metadata` optionally to include any other data you want to send along with the message. This field provides a mechanism for developers to extend chat message functionality and add custom information for your use case. For example, when sharing a file link in the message, you might want to add 'hasAttachment: true' in metadata so that recipient's application can parse that and display accordingly. Please refer to the [following tutorial](../file-sharing-tutorial-acs-chat.md).
275+
- Use `senderDisplayName` to specify the display name of the sender.
276+
- Use `type` to specify the message type, such as `text` or `html`.
257277

258-
`SendChatMessageResult` is the response returned from sending a message, it contains an ID, which is the unique ID of the message.
278+
To recreate the "Media" property in Twilio.
279+
- Use `metadata` optionally to include any other data you want to send along with the message. This field enables developers to extend the chat message function and add custom information for your use case. For example, when sharing a file link in the message, you might want to add `hasAttachment: true` in metadata so that recipient's application can parse that and display accordingly. For more information, see [File sharing](../file-sharing-tutorial-acs-chat.md).
280+
281+
`SendChatMessageResult` is the response returned from sending a message. It contains an ID, which is the unique ID of the message.
259282

260283
```JavaScript
261284
const sendMessageRequest =
@@ -277,10 +300,13 @@ console.log(`Message sent!, message id:${messageId}`);
277300
```
278301

279302
### Receive chat messages from a chat thread
280-
Unlike Twilio, ACS does not have separate functions to receive text messages or media. Azure Communication Services uses Azure Event Grid to handle events. To learn more, please refer to [following tutorial](MicrosoftDocs/azure-docs-pr/articles/event-grid/event-schema-communication-services.md)
303+
304+
Unlike Twilio, Azure Communication Services doesn't have separate functions to receive text messages or media. Azure Communication Services uses Azure Event Grid to handle events. For more information, see [Event Handling](/azure/event-grid/event-schema-communication-services.md).
281305

282306
#### Twilio
283-
This is how you receive a text message in Twilio.
307+
308+
To receive a text message in Twilio.
309+
284310
```JavaScript
285311
// Receive text message
286312
let paginator =
@@ -290,7 +316,8 @@ This is how you receive a text message in Twilio.
290316

291317
const messages = paginator.items;
292318
```
293-
This is how you receive media in Twilio.
319+
320+
To receive media in Twilio.
294321

295322
```JavaScript
296323
// Receive media
@@ -302,7 +329,8 @@ const mediaUrl = await media[0].getContentTemporaryUrl();
302329
```
303330

304331
#### Azure Communication Services
305-
With real-time signaling, you can subscribe to listen for new incoming messages and update the current messages in memory accordingly. Azure Communication Services supports a [list of events that you can subscribe to](../../../concepts/chat/concepts.md#real-time-notifications).
332+
333+
With real-time signaling, you can subscribe to listen for new incoming messages and update the current messages in memory accordingly. Azure Communication Services supports a [list of events that you can subscribe to](../../concepts/chat/concepts.md#real-time-notifications).
306334

307335
```JavaScript
308336
// open notifications channel
@@ -325,15 +353,16 @@ for await (const message of messages) {
325353
}
326354

327355
```
328-
`listMessages` returns different types of messages that can be identified by `chatMessage.type`.
329356

330-
For more details, see [Message Types](../../../concepts/chat/concepts.md#message-types).
357+
`listMessages` returns different types of messages that you can identify by `chatMessage.type`.
331358

359+
For more information, see [Message Types](../../concepts/chat/concepts.md#message-types).
332360

333361
#### Subscribe to connection status of real time notifications
334-
Similar to Twilio, Azure Communication Services allows you to subscribe to event notifications.
335362

336-
Subscription to events `realTimeNotificationConnected` and `realTimeNotificationDisconnected` allows you to know when the connection to the call server is active.
363+
Similar to Twilio, Azure Communication Services enables you to subscribe to event notifications.
364+
365+
Subscribing to events `realTimeNotificationConnected` and `realTimeNotificationDisconnected` lets you know when the connection to the call server is active.
337366

338367
```JavaScript
339368
// subscribe to realTimeNotificationConnected event

0 commit comments

Comments
 (0)