Skip to content

Commit 526eb88

Browse files
authored
review and acrolinx
1 parent f44082e commit 526eb88

File tree

1 file changed

+55
-39
lines changed

1 file changed

+55
-39
lines changed

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

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Migrating from Twilio Conversations Chat to ACS Chat C#
2+
title: Migrating from Twilio Conversations Chat to Azure Communication Services Chat C#
33
description: Guide describes how to migrate C# apps from Twilio Conversations Chat to Azure Communication Services Chat SDK.
44
services: azure-communication-services
55
ms.date: 07/22/2024
@@ -12,45 +12,50 @@ ms.custom: mode-other
1212
---
1313

1414
## Prerequisites
15-
Before you get started, make sure to:
16-
- Create an Azure account with an active subscription. For details, see [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
17-
- Install [Visual Studio](https://visualstudio.microsoft.com/downloads/)
18-
- Create an Azure Communication Services resource. For details, see [Create an Azure Communication Services resource](../../create-communication-resource.md). You'll need to record your resource **endpoint and connection string** for this quickstart.
19-
- A [User Access Token](../../identity/access-tokens.md). Be sure to set the scope to **chat**, and **note the token string as well as the user_id string**. You can also use the Azure CLI and run the command below with your connection string to create a user and an access token.
15+
16+
1. Create an Azure account with an active subscription. For details, see [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
17+
2. Install [Visual Studio](https://visualstudio.microsoft.com/downloads/).
18+
3. Create an Azure Communication Services resource. For details, see [Create an Azure Communication Services resource](../../quickstarts/create-communication-resource.md). Record your resource **endpoint and connection string**.
19+
4. A [User Access Token](../../quickstarts/identity/access-tokens.md). Be sure to set the scope to **chat**, and **note the token string and user_id string**. You can also use the Azure CLI and run the command below with your connection string to create a user and an access token.
2020

2121
```azurecli-interactive
2222
az communication identity token issue --scope chat --connection-string "yourConnectionString"
2323
```
2424

25-
For details, see [Use Azure CLI to Create and Manage Access Tokens](../../identity/access-tokens.md?pivots=platform-azcli).
25+
For more information, see [Use Azure CLI to Create and Manage Access Tokens](../../quickstarts/identity/access-tokens.md?pivots=platform-azcli).
2626

2727
## Conceptual Difference
28-
While both Twilio Conversations and ACS Chat offer similar functionalities, their implementation differs due to the surrounding ecosystems and underlying platform philosophies. Twilio Conversations provides a multi-channel communication API, whereas ACS Chat is focused primarily on chat within the Azure ecosystem. This migration guide provides a basic mapping between common operations in Twilio and their equivalents in ACS Chat, helping you transition your .NET code more smoothly.
28+
29+
Both Twilio Conversations and Azure Communication Services Chat offer similar functions, but their implementation differs due to the surrounding ecosystems and underlying platform philosophies. Twilio Conversations provide a multi-channel communication API. Azure Communication Services Chat is focused primarily on chat within the Azure ecosystem. This migration guide provides a basic mapping between common operations in Twilio and their equivalents in Azure Communication Services Chat, helping you transition your .NET code.
2930

3031
### Identities
32+
3133
#### Twilio
3234

3335
Twilio Conversations uses identity strings directly.
3436

3537
#### Azure Communication Services
3638

37-
ACS requires creating users through the CommunicationIdentityClient.
39+
Azure Communication Services requires creating users through the `CommunicationIdentityClient`.
3840

3941
## Setting up
42+
4043
### Install the package
44+
4145
To start the migration from Twilio Conversations chat, the first step is to install the Azure Communication Services Chat SDK for .NET to your project.
4246

4347
```PowerShell
4448
dotnet add package Azure.Communication.Chat
4549
```
4650

4751
## Object model
52+
4853
The following classes handle some of the major features of the Azure Communication Services Chat SDK for C#.
4954

5055
| Name | Description |
5156
| ------------------------------------- | ------------------------------------------------------------ |
52-
| ChatClient | This class is needed for the Chat functionality. You instantiate it with your subscription information, and use it to create, get and delete threads. |
53-
| 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 participants, send typing notifications and read receipts. |
57+
| `ChatClient` | This class is needed for the Chat functionality. You instantiate it with your subscription information, and use it to create, get and delete threads. |
58+
| `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 participants, send typing notifications and read receipts. |
5459

5560
## Create a chat client
5661

@@ -64,9 +69,9 @@ var twilio = new TwilioRestClient(accountSid, authToken);
6469

6570
#### Azure Communication Services
6671

67-
To create a chat client in Azure Communication Services, you'll use your Communication Services endpoint and the access token that was generated as part of the prerequisite steps. You need to use the `CommunicationIdentityClient` class from the Identity SDK to create a user and issue a token to pass to your chat client.
72+
To create a chat client in Azure Communication Services, use your Communication Services endpoint and the access token that was generated as part of the prerequisite steps. You need to use the `CommunicationIdentityClient` class from the Identity SDK to create a user and issue a token to pass to your chat client.
6873

69-
Learn more about [User Access Tokens](../../identity/access-tokens.md).
74+
Learn more about [User Access Tokens](../../quickstarts/identity/access-tokens.md).
7075

7176
```csharp
7277
// Your unique Azure Communication service endpoint
@@ -88,13 +93,13 @@ var conversation = ConversationResource.Create(
8893

8994
#### Azure Communication Services
9095

91-
In ACS, you create a thread, which is equivalent to a conversation in Twilio.
96+
In Azure Communication Services, you create a thread, which is equivalent to a conversation in Twilio.
9297

9398
Use the `createChatThread` method on the chatClient to create a chat thread
94-
- Use `topic` to give a topic to this chat; Topic can be updated after the chat thread is created using the `UpdateTopic` function.
95-
- Use `participants` property to pass a list of `ChatParticipant` objects to be added to the chat thread. The `ChatParticipant` object is initialized with a `CommunicationIdentifier` object. `CommunicationIdentifier` could be of type `CommunicationUserIdentifier`, `MicrosoftTeamsUserIdentifier` or `PhoneNumberIdentifier`. For example, to get a `CommunicationIdentifier` object, you'll need to pass an Access ID which you created by following instruction to [Create a user](../../identity/access-tokens.md#create-an-identity)
99+
- Use `topic` to give a topic to this chat; you can update the `topic` after the chat thread is created using the `UpdateTopic` function.
100+
- Use `participants` property to pass a list of `ChatParticipant` objects to be added to the chat thread. Initialize the `ChatParticipant` object with a `CommunicationIdentifier` object. `CommunicationIdentifier` could be of type `CommunicationUserIdentifier`, `MicrosoftTeamsUserIdentifier`, or `PhoneNumberIdentifier`. For example, to get a `CommunicationIdentifier` object, you need to pass an Access ID created following the instructions to [Create a user](../../quickstarts/identity/access-tokens.md#create-an-identity).
96101

97-
The response object from the `createChatThread` method contains the `chatThread` details. To interact with the chat thread operations such as adding participants, sending a message, deleting a message, etc., a `chatThreadClient` client instance needs to instantiated using the `GetChatThreadClient` method on the `ChatClient` client.
102+
The response object from the `createChatThread` method contains the `chatThread` details. To interact with the chat thread operations such as adding participants, sending a message, deleting a message, and so on, instantiate a `chatThreadClient` client instance using the `GetChatThreadClient` method on the `ChatClient` client.
98103

99104
```csharp
100105
var chatParticipant = new ChatParticipant(identifier: new CommunicationUserIdentifier(id: "<Access_ID>"))
@@ -109,7 +114,8 @@ string threadId = chatThreadClient.Id;
109114
### Get a chat thread client
110115

111116
##### Twilio
112-
In Twilio Conversations, you interact directly with a conversation using the conversation's SID (unique identifier). Here's how you would typically get a conversation and interact with it:
117+
118+
In Twilio Conversations, you interact directly with a conversation using the conversation's SID (unique identifier). Here's how to typically get a conversation and interact with it:
113119

114120
```csharp
115121
var conversationSid = "<CONVERSATION_SID>";
@@ -125,7 +131,7 @@ foreach (var message in messages)
125131

126132
#### Azure Communication Services
127133

128-
The `GetChatThreadClient` method returns a thread client for a thread that already exists. It can be used for performing operations on the created thread: add members, send message, etc. threadId is the unique ID of the existing chat thread.
134+
The `GetChatThreadClient` method returns a thread client for a thread that already exists. You can use it to perform operations on the created thread: add members, send message, and so on. `threadId` is the unique ID of the existing chat thread.
129135

130136
```csharp
131137
string threadId = "<THREAD_ID>";
@@ -135,7 +141,8 @@ ChatThreadClient chatThreadClient = chatClient.GetChatThreadClient(threadId: thr
135141
### List all chat threads
136142

137143
##### Twilio
138-
In Twilio Conversations, you can retrieve all conversations that a user is a participant in by querying the UserConversations resource. This resource provides a list of conversations for a specific user.
144+
145+
In Twilio Conversations, you can retrieve all conversations that a user is a participant in by querying the `UserConversations` resource. This resource provides a list of conversations for a specific user.
139146

140147
```csharp
141148
/ Initialize Twilio Client
@@ -173,15 +180,19 @@ await foreach (ChatThreadItem chatThreadItem in chatThreadItems)
173180
### Send a message to a chat thread
174181

175182
##### Twilio
183+
176184
The following code snippet shows how to send a text message.
185+
177186
```csharp
178187
var message = MessageResource.Create(
179188
body: "Hello, world!",
180189
181190
pathConversationSid: conversation.Sid
182191
);
183192
```
184-
The code snippet below shows how to send a media file.
193+
194+
The following code snippet shows how to send a media file.
195+
185196
```csharp
186197
// The SID of the conversation you want to send the media message to
187198
string conversationSid = "<CONVERSATION_SID>";
@@ -201,16 +212,15 @@ var message = MessageResource.Create(
201212
);
202213
```
203214

204-
#### Azure Communication Services
205-
Unlike Twilio, ACS does not have a separate function to send text messages or media.
215+
#### Azure Communication Services
206216

217+
Unlike Twilio, Azure Communication Services does not have a separate function to send text messages or media.
207218

208219
Use `SendMessage` to send a message to a thread.
209-
210220
- Use `content` to provide the content for the message, it's required.
211-
- Use `type` for the content type of the message such as 'Text' or 'Html'. If not specified, 'Text' will be set.
212-
- Use `senderDisplayName` to specify the display name of the sender. If not specified, empty string will be set.
213-
- Use `metadata` optionally to include any additional 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.
221+
- Use `type` for the content type of the message such as `Text` or `Html`. If not specified, `Text` is the default.
222+
- Use `senderDisplayName` to specify the display name of the sender. If not specified, empty string is the default.
223+
- Use `metadata` optionally to include any additional data you want to send along with the message. This field provides a mechanism for developers to extend 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 the metadata so that recipient's application can parse that and display accordingly.
214224

215225
```csharp
216226
SendChatMessageOptions sendChatMessageOptions = new SendChatMessageOptions()
@@ -227,10 +237,13 @@ string messageId = sendChatMessageResult.Id;
227237
```
228238

229239
### Receive chat messages from a chat thread
240+
230241
##### Twilio
242+
231243
Twilio typically uses webhooks to notify your server of incoming messages:
232244

233245
The following code snippet shows how to receive a text message.
246+
234247
```csharp
235248
public IActionResult ReceiveMessage()
236249
{
@@ -253,10 +266,11 @@ The following code snippet shows how to receive a media file.
253266
}
254267
```
255268

269+
#### Azure Communication Services
256270

257-
#### Azure Communication Services
258-
Unlike Twilio, ACS does not have a separate function to receive text messages or media.
259-
ACS Chat allows you to subscribe to events directly within the application.
271+
Unlike Twilio, Azure Communication Services does not have a separate function to receive text messages or media.
272+
273+
Azure Communication Services Chat enables you to subscribe to events directly within the application.
260274

261275
You can retrieve chat messages by polling the `GetMessages` method on the chat thread client at specified intervals.
262276

@@ -268,25 +282,26 @@ await foreach (ChatMessage message in allMessages)
268282
}
269283
```
270284

271-
`GetMessages` takes an optional `DateTimeOffset` parameter. If that offset is specified, you'll receive messages that were received, updated or deleted after it. Note that messages received before the offset time but edited or removed after it will also be returned.
285+
`GetMessages` takes an optional `DateTimeOffset` parameter. If that offset is specified, you receive messages that were received, updated, or deleted after it. Note that messages received before the offset time but edited or removed after it are also be returned.
272286

273-
`GetMessages` returns the latest version of the message, including any edits or deletes that happened to the message using `UpdateMessage` and `DeleteMessage`. For deleted messages, `chatMessage.DeletedOn` returns a datetime value indicating when that message was deleted. For edited messages, `chatMessage.EditedOn` returns a datetime indicating when the message was edited. The original time of message creation can be accessed using `chatMessage.CreatedOn`, and it can be used for ordering the messages.
287+
`GetMessages` returns the latest version of the message, including any edits or deletes that happened to the message using `UpdateMessage` and `DeleteMessage`. For deleted messages, `chatMessage.DeletedOn` returns a datetime value indicating when that message was deleted. For edited messages, `chatMessage.EditedOn` returns a datetime indicating when the message was edited. You can access the original time of message creation using `chatMessage.CreatedOn`, and use it for ordering the messages.
274288

275289
`GetMessages` returns different types of messages which can be identified by `chatMessage.Type`. These types are:
276290

277291
- `Text`: Regular chat message sent by a thread member.
278292

279-
- `Html`: A formatted text message. Note that Communication Services users currently can't send RichText messages. This message type is supported by messages sent from Teams users to Communication Services users in Teams Interop scenarios.
293+
- `Html`: A formatted text message. Note that Communication Services users currently can't send `RichText` messages. This message type is supported by messages sent from Teams users to Communication Services users in Teams Interop scenarios.
280294

281295
- `TopicUpdated`: System message that indicates the topic has been updated. (readonly)
282296

283-
- `ParticipantAdded`: System message that indicates one or more participants have been added to the chat thread.(readonly)
297+
- `ParticipantAdded`: System message that indicates one or more participants have been added to the chat thread. (readonly)
284298

285299
- `ParticipantRemoved`: System message that indicates a participant has been removed from the chat thread.
286300

287-
For more details, see [Message Types](../../../concepts/chat/concepts.md#message-types).
301+
For more information, see [Message Types](../../concepts/chat/concepts.md#message-types).
288302

289303
### Add a user as a participant to the chat thread
304+
290305
#### Twilio
291306

292307
```csharp
@@ -298,8 +313,9 @@ var participant = ParticipantResource.Create(
298313

299314
#### Azure Communication Services
300315

301-
In ACS, you add participants when creating the chat thread or afterwards:
302-
Once a thread is created, you can then add and remove users from it. By adding users, you give them access to be able to send messages to the thread, and add/remove other participant. Before calling `AddParticipants`, ensure that you have acquired a new access token and identity for that user. The user will need that access token in order to initialize their chat client.
316+
In Azure Communication Services, you add participants when creating the chat thread or afterwards:
317+
318+
Once you create a thread, you can add and remove users. Adding users gives them access to send messages to the thread, and add/remove other participants. Before calling `AddParticipants`, ensure that you acquire a new access token and identity for that user. The user needs the access token to initialize their chat client.
303319

304320
Use `AddParticipants` to add one or more participants to the chat thread. The following are the supported attributes for each thread participant(s):
305321
- `communicationUser`, required, is the identity of the thread participant.
@@ -324,7 +340,8 @@ await chatThreadClient.AddParticipantsAsync(participants: participants);
324340
### Get thread participants
325341

326342
##### Twilio
327-
In Twilio Conversations, you use the ConversationResource to retrieve the participants of a specific conversation. You can then list all participants associated with that conversation.
343+
344+
In Twilio Conversations, you use the `ConversationResource` to retrieve the participants of a specific conversation. You can then list all participants associated with that conversation.
328345

329346
```csharp
330347
// The SID of the conversation you want to retrieve participants from
@@ -378,4 +395,3 @@ Use `SendReadReceipt` to notify other participants that the message is read by t
378395
```csharp
379396
await chatThreadClient.SendReadReceiptAsync(messageId: messageId);
380397
```
381-

0 commit comments

Comments
 (0)