You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/communication-services/tutorials/includes/twilio-to-acs-chat-ios-tutorial.md
+58-37Lines changed: 58 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
---
2
-
title: Migrating from Twilio Conversations Chat to ACS Chat iOS
2
+
title: Migrating from Twilio Conversations Chat to Azure Communication Services Chat iOS
3
3
description: Guide describes how to migrate iOS apps from Twilio Conversations Chat to Azure Communication Services Chat SDK.
4
4
services: azure-communication-services
5
5
ms.date: 07/22/2024
@@ -28,9 +28,9 @@ For more information, see [Use Azure CLI to Create and Manage Access Tokens](../
28
28
29
29
### Install the libraries
30
30
31
-
To start the migration from Twilio Conversations Chat, the first step is to install the Azure Communication Services Chat SDK for iOS to your project. You can configure these parameters using`Cocoapods`.
31
+
To start the migration from Twilio Conversations Chat, the first step is to install the Azure Communication Services Chat SDK for iOS to your project. You can configure these parameters using`Cocoapods`.
32
32
33
-
1.To create a Podfile for your application, open the terminal and navigate to the project folder and run:
33
+
1.Create a Podfile for your application. Open the terminal, navigate to the project folder, and run:
34
34
35
35
`pod init`
36
36
@@ -40,17 +40,17 @@ To start the migration from Twilio Conversations Chat, the first step is to inst
40
40
pod 'AzureCommunicationChat', '~> 1.3.5'
41
41
```
42
42
43
-
3. Set up the `.xcworkspace` project
43
+
3. Set up the `.xcworkspace` project:
44
44
45
45
```shell
46
46
pod install
47
47
```
48
48
49
-
4. Open the `.xcworkspace`that was created by the pod install with Xcode.
49
+
4. Open the `.xcworkspace` created by the pod install with Xcode.
50
50
51
51
### Authenticating to the SDK
52
52
53
-
To be able to use the Azure Communication Services Chat SDK, you need to authenticate using an access token.
53
+
To use the Azure Communication Services Chat SDK, you need to authenticate using an access token.
54
54
55
55
#### Twilio
56
56
@@ -96,7 +96,8 @@ callClient.createCallAgent(userCredential: userCredential) { callAgent, error in
96
96
97
97
#### Twilio
98
98
99
-
The following code snippet helps to initialize chat client in Twilio.
99
+
The following code snippet initializes the chat client in Twilio.
100
+
100
101
```swift
101
102
funcfetchAccessTokenAndInitializeClient() {
102
103
let identity ="user_identity"// Replace with actual user identity
To create a chat client, you'll use your Communication Services endpoint and the access token that was generated as part of the prerequisite steps.
131
+
To create a chat client, use your Communication Services endpoint and the access token generated as part of the prerequisite steps.
132
+
131
133
Replace `<ACS_RESOURCE_ENDPOINT>` with the endpoint of your Azure Communication Services resource. Replace `<ACCESS_TOKEN>` with a valid Communication Services access token.
132
134
133
135
```swift
@@ -151,14 +153,16 @@ The following classes and interfaces handle some of the major features of the Az
|`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. |
155
-
|`ChatThreadClient`| This class is needed for the chat thread functionality. You obtain an instance via `ChatClient`, and use it to send, receive, update, and delete messages. You can also use it to add, remove, and get users, send typing notifications and read receipts. |
156
+
|`ChatClient`| This class is needed for the chat function. You instantiate it with your subscription information, and use it to create, get, delete threads, and subscribe to chat events. |
157
+
|`ChatThreadClient`| This class is needed for the chat thread function. You get an instance via `ChatClient`, and use it to send, receive, update, and delete messages. You can also use it to add, remove, get users, and send typing notifications and read receipts. |
156
158
157
159
158
160
### Start a chat thread
159
161
160
162
#### Twilio
161
-
The following code snippet allow to create a new chat thread
163
+
164
+
The following code snippet enables you to create a new chat thread.
165
+
162
166
```swift
163
167
// the unique name of the conversation you create
164
168
privatelet uniqueConversationName ="general"
@@ -191,10 +195,11 @@ The following code snippet allow to create a new chat thread
191
195
```
192
196
193
197
#### Azure Communication Services
194
-
`CreateChatThreadResult` is the response returned from creating a chat thread.
195
-
It contains a `chatThread` property which is the `ChatThreadProperties` object. This object contains the threadId which can be used to get a `ChatThreadClient` for performing operations on the created thread: add participants, send message, etc.
196
198
197
-
Replace the comment `<CREATE A CHAT THREAD>` with the code snippet below:
199
+
The response returned from creating a chat thread is `CreateChatThreadResult`.
200
+
It contains a `chatThread` property, which is the `ChatThreadProperties` object. This object contains the `threadId`, which you can use to get a `ChatThreadClient` for performing operations on the created thread: add participants, send message, and so on.
201
+
202
+
Replace the comment `<CREATE A CHAT THREAD>` with the following code snippet:
198
203
199
204
```swift
200
205
let request =CreateChatThreadRequest(
@@ -223,14 +228,15 @@ semaphore.wait()
223
228
224
229
Replace `<USER_ID>` with a valid Communication Services user ID.
225
230
226
-
You're using a semaphore here to wait for the completion handler before continuing. In later steps, you'll use the `threadId` from the response returned to the completion handler.
231
+
You're using a semaphore here to wait for the completion handler before continuing. In later steps, use the `threadId` from the response returned to the completion handler.
227
232
228
233
229
234
### Get a chat thread client
230
235
231
236
#### Twilio
232
237
233
-
The following code snippet showes how to get chat thread client in Twilio.
238
+
The following code snippet shows how to get a chat thread client in Twilio.
The `createClient` 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.
261
+
262
+
The `createClient` method returns a `ChatThreadClient` for a thread that already exists. You can use it to perform operations on the created thread: add participants, send message, and so on.
263
+
264
+
The `threadId` is the unique ID of the existing chat thread.
256
265
257
266
Replace the comment `<GET A CHAT THREAD CLIENT>` with the following code:
258
267
@@ -261,10 +270,13 @@ let chatThreadClient = try chatClient.createClient(forThread: threadId!)
261
270
```
262
271
263
272
### Send a message to a chat thread
264
-
Unlike Twilio ACS does not have separate function to send text message or media.
273
+
274
+
Unlike Twilio, Azure Communication Services doesn't have separate function to send text message or media.
Use the `send` method to send a message to a thread identified by threadId.
313
325
314
-
`SendChatMessageRequest` is used to describe the message request:
326
+
Use the `send` method to send a message to a thread identified by `threadId`.
327
+
328
+
Use `SendChatMessageRequest` to describe the message request:
315
329
316
-
- Use `content` to provide the chat message content
317
-
- Use `senderDisplayName` to specify the display name of the sender
318
-
- Use `type` to specify the message type, such as'text' or 'html'
319
-
- Use `metadata` optionally to include anyadditional 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.
330
+
- Use `content` to provide the chat message content.
331
+
- Use `senderDisplayName` to specify the display name of the sender.
332
+
- Use `type` to specify the message type, such as`text` or `html`.
333
+
- Use `metadata` optionally to include anyinformation 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.
320
334
321
-
`SendChatMessageResult` is the response returned from sending a message, it contains an ID, which is the unique ID of the message.
335
+
The response returned from sending a messageis`SendChatMessageResult`. It contains an ID, which is the unique ID of the message.
322
336
323
-
Replace the comment `<SEND A MESSAGE>` with the code snippet below:
337
+
Replace the comment `<SEND A MESSAGE>` with the following code snippet:
324
338
325
339
```swift
326
340
let message =SendChatMessageRequest(
@@ -349,10 +363,13 @@ semaphore.wait()
349
363
```
350
364
351
365
### Receive chat messages from a chat thread
352
-
Unlike Twilio ACS does not have separate function to receive text message or media.
366
+
367
+
Unlike Twilio, Azure Communication Services doesn't have a separate function to receive text message or media.
353
368
354
369
#### Twilio
355
-
Code snippet below shows how to receive text message in Twilio.
370
+
371
+
The following code snippet shows how to receive a text message in Twilio.
372
+
356
373
```swift
357
374
// Called whenever a conversation we've joined receives a new message
@@ -369,7 +386,8 @@ Code snippet below shows how to receive text message in Twilio.
369
386
}
370
387
```
371
388
372
-
Receive media
389
+
Receive media in Twilio:
390
+
373
391
```swift
374
392
conversationsClient.getTemporaryContentUrlsForMedia(message.attachedMedia) { result, mediaSidToUrlMap in
375
393
guard result.isSuccessful else {
@@ -384,9 +402,10 @@ conversationsClient.getTemporaryContentUrlsForMedia(message.attachedMedia) { res
384
402
```
385
403
386
404
#### Azure Communication Services
387
-
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).
388
405
389
-
Replace the comment `<RECEIVE MESSAGES>` with the code below. After enabling notifications, try sending new messages to see the ChatMessageReceivedEvents.
406
+
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).
407
+
408
+
Replace the comment `<RECEIVE MESSAGES>` with the following code. After enabling notifications, try sending new messages to see the `ChatMessageReceivedEvents`.
390
409
391
410
```swift
392
411
chatClient.startRealTimeNotifications { result in
@@ -410,7 +429,7 @@ chatClient.register(event: .chatMessageReceived, handler: { response in
410
429
})
411
430
```
412
431
413
-
Alternatively you can retrieve chat messages by polling the `listMessages` method at specified intervals. See the following code snippet for `listMessages`
432
+
Alternatively you can retrieve chat messages by polling the `listMessages` method at specified intervals. See the following code snippet for `listMessages`.
414
433
415
434
```swift
416
435
chatThreadClient.listMessages { result, _in
@@ -435,7 +454,9 @@ semaphore.wait()
435
454
436
455
### Push notifications
437
456
438
-
Similar to Twilio Azure Communication Services support push notifications. Push notifications notify clients of incoming messages in a chat thread in situations where the mobile app is not running in the foreground.
439
-
Currently sending chat push notifications with Notification Hub is supported for IOS SDK in version 1.3.0.
440
-
Please refer to the article [Enable Push Notification in your chat app](../../../tutorials/add-chat-push-notifications.md) for details.
457
+
Similar to Twilio, Azure Communication Services support push notifications. Push notifications notify clients of incoming messages in a chat thread if the mobile app isn't running in the foreground.
458
+
459
+
Currently sending chat push notifications with Notification Hub is supported for iOS SDK in version 1.3.0.
460
+
461
+
For more information, see [Enable Push Notification in your chat app](../../tutorials/add-chat-push-notifications.md).
0 commit comments