Skip to content

Commit da695c9

Browse files
authored
Merge pull request #274600 from paulth1/two-chat-sdk-tutorials
[AQ] edit pass: Two chat sdk tutorials
2 parents 8727775 + da6c8bc commit da695c9

6 files changed

+187
-191
lines changed

articles/communication-services/tutorials/chat-interop/includes/meeting-interop-features-file-attachment-csharp.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
---
2-
title: Tutorial - Enable File Attachment Support
2+
title: Tutorial - Enable file attachment support
33
author: jpeng-ms
44
ms.author: jopeng
55
ms.date: 04/10/2024
66
ms.topic: include
77
ms.service: azure-communication-services
88
---
99

10-
This tutorial describes how to enable file attachment support using the Azure Communication Services Chat SDK for C#.
10+
This tutorial describes how to enable file attachment support by using the Azure Communication Services Chat SDK for C#.
1111

12-
## Sample code
13-
Find the finalized code for this tutorial at [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/ChatTeamsInteropQuickStart).
12+
In this tutorial, you learn how to:
13+
14+
- Handle file attachments.
15+
- Handle image attachments.
1416

15-
## Prerequisites
17+
## Prerequisites
1618

17-
* Complete the quickstart [Join your chat app to a Teams meeting](../../../quickstarts/chat/meeting-interop.md).
18-
* Create an Azure Communication Services resource as described in [Create an Azure Communication Services resource](../../../quickstarts/create-communication-resource.md). You need to **record your connection string** for this tutorial.
19-
* Set up a Teams meeting using your business account and have the meeting URL ready.
20-
* Download the Chat SDK for C# (@azure/communication-chat) 1.3.0 or the latest. See [Azure Communication Chat client library](https://www.nuget.org/packages/Azure.Communication.Chat).
19+
* Review the quickstart [Join your Chat app to a Teams meeting](../../../quickstarts/chat/meeting-interop.md).
20+
* Create an Azure Communication Services resource as described in [Create an Azure Communication Services resource](../../../quickstarts/create-communication-resource.md). You need to *record your connection string* for this tutorial.
21+
* Set up a Teams meeting by using your business account and have the meeting URL ready.
22+
* Download the Chat SDK for C# (@azure/communication-chat) 1.3.0 or the latest. For more information, see [Azure Communication Chat client library](https://www.nuget.org/packages/Azure.Communication.Chat).
23+
24+
## Sample code
25+
Find the finalized code for this tutorial at [GitHub](https://github.com/Azure-Samples/communication-services-dotnet-quickstarts/tree/main/ChatTeamsInteropQuickStart).
2126

2227
## Handle file attachments
2328

24-
The Chat SDK for C# returns a `ChatAttachmentType` of `file` for regular file attachments and `image` for inline images.
29+
The Chat SDK for C# returns a `ChatAttachmentType` property of `file` for regular file attachments and `image` for inline images.
2530

2631
```csharp
2732
public readonly partial struct ChatAttachmentType : IEquatable<ChatAttachmentType>
@@ -37,7 +42,7 @@ public readonly partial struct ChatAttachmentType : IEquatable<ChatAttachmentTyp
3742

3843
```
3944

40-
For example, the following JSON shows what `ChatAttachment` might look like for an image attachment and a file attachment when receiving requests from the server side:
45+
For example, the following JSON shows what `ChatAttachment` might look like for an image attachment and a file attachment when you receive requests from the server side:
4146

4247
```json
4348
"attachments": [
@@ -57,7 +62,7 @@ For example, the following JSON shows what `ChatAttachment` might look like for
5762
]
5863
```
5964

60-
Now let's go back to the event handler we created in previous [quickstart](../../../quickstarts/chat/meeting-interop.md) and add some extra logic to handle attachments with `ChatAttachmentType` of `file`:
65+
Now go back to the event handler you created in the previous [quickstart](../../../quickstarts/chat/meeting-interop.md) and add some extra logic to handle attachments with the `ChatAttachmentType` property of `file`:
6166

6267
```csharp
6368

@@ -87,19 +92,19 @@ await foreach (ChatMessage message in allMessages)
8792

8893
```
8994

90-
Specifically, for each file attachment, we get the `previewUrl` and construct a list of URLs in the `for loop`. Then we embed the string along with the chat message content.
95+
Specifically, for each file attachment, you get the `previewUrl` property and construct a list of URLs in the `for loop`. Then you embed the string along with the Chat message content.
9196

9297
## Handle image attachments
9398

94-
You need to handle image attachments differently than standard `file` attachments. Image attachments have the `ChatAttachmentType` of `image`, which requires the communication token to retrieve either the preview or full-size images.
99+
You need to handle image attachments differently than standard `file` attachments. Image attachments have the `ChatAttachmentType` property of `image`, which requires the communication token to retrieve either the preview or full-size images.
95100

96-
Before continuing, complete the [Enabling inline image support](../meeting-interop-features-inline-image.md) tutorial. To identity image attachments, we need to find out if the message content contains the same image ID from the attachments.
101+
Before you continue, finish the [Enable inline image support](../meeting-interop-features-inline-image.md) tutorial. To identity image attachments, you need to find out if the message content contains the same image ID from the attachments.
97102

98103
```csharp
99104
bool isImageAttachment = message.Content.Message.Contains(x.Id);
100105
```
101106

102-
If this flag is true, then we should apply inline image logic to render it:
107+
If this flag is true, then you apply inline image logic to render it:
103108

104109
```csharp
105110
IEnumerable<ChatAttachment> imageAttachments = message.Content.Attachments.Where(x => x.AttachmentType == ChatAttachmentType.Image);

articles/communication-services/tutorials/chat-interop/includes/meeting-interop-features-file-attachment-javascript.md

Lines changed: 39 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
---
2-
title: Tutorial - Enable File Attachment Support
2+
title: Tutorial - Enable file attachment support
33
author: jpeng-ms
44
ms.author: jopeng
55
ms.date: 05/26/2023
66
ms.topic: include
77
ms.service: azure-communication-services
88
---
99

10-
This tutorial describes how to enable file attachment support using the Azure Communication Services Chat SDK for JavaScript.
10+
This tutorial describes how to enable file attachment support by using the Azure Communication Services Chat SDK for JavaScript.
1111

1212
## Sample code
1313
Find the finalized code of this tutorial on [GitHub](https://github.com/Azure-Samples/communication-services-javascript-quickstarts/tree/main/join-chat-to-teams-meeting).
1414

15-
## Prerequisites
15+
## Prerequisites
1616

17-
* You've gone through the quickstart - [Join your chat app to a Teams meeting](../../../quickstarts/chat/meeting-interop.md).
18-
* Create an Azure Communication Services resource. For details, see [Create an Azure Communication Services resource](../../../quickstarts/create-communication-resource.md). You need to **record your connection string** for this tutorial.
19-
* You've set up a Teams meeting using your business account and have the meeting URL ready.
20-
* You're using the Chat SDK for JavaScript (@azure/communication-chat) 1.5.0 or the latest. See [here](https://www.npmjs.com/package/@azure/communication-chat).
17+
* Review the quickstart [Join your Chat app to a Teams meeting](../../../quickstarts/chat/meeting-interop.md).
18+
* Create an Azure Communication Services resource. For more information, see [Create an Azure Communication Services resource](../../../quickstarts/create-communication-resource.md). You need to *record your connection string* for this tutorial.
19+
* Set up a Teams meeting by using your business account and have the meeting URL ready.
20+
* Use the Chat SDK for JavaScript (@azure/communication-chat) 1.5.0 or the latest. For more information, see [Azure Communication Chat client library for JavaScript](https://www.npmjs.com/package/@azure/communication-chat).
2121

2222
## Goals
2323

@@ -26,7 +26,7 @@ Find the finalized code of this tutorial on [GitHub](https://github.com/Azure-Sa
2626

2727
## Handle file attachments
2828

29-
The Chat SDK for JavaScript returns a `ChatAttachmentType` of `file` for regular file attachments and `image` for message-inlined images.
29+
The Chat SDK for JavaScript returns a `ChatAttachmentType` property of `file` for regular file attachments and `image` for message-inlined images.
3030

3131
```js
3232
export interface ChatMessageReceivedEvent extends BaseChatMessageEvent {
@@ -50,13 +50,13 @@ export interface ChatAttachment {
5050
attachmentType: AttachmentType;
5151
/** The name of the attachment content. */
5252
name?: string;
53-
/** The URL that is used to provide original size of the inline images */
53+
/** The URL that is used to provide the original size of the inline images */
5454
url?: string;
55-
/** The URL that provides the preview of attachment */
55+
/** The URL that provides the preview of the attachment */
5656
previewUrl?: string;
5757
}
5858

59-
/** Type of Supported Attachments. */
59+
/** Type of supported attachments. */
6060
export type ChatAttachmentType = "image" | "file" | "unknown";
6161
```
6262

@@ -80,12 +80,12 @@ For example, the following JSON shows what `ChatAttachment` might look like for
8080
]
8181
```
8282

83-
Now let's go back to event handler we created in [Quickstart: Join your chat app to a Teams meeting](../../../quickstarts/chat/meeting-interop.md) and add some extra logic to handle attachments with `attachmentType` of `file`:
83+
Now let's go back to the event handler you created in [Quickstart: Join your Chat app to a Teams meeting](../../../quickstarts/chat/meeting-interop.md) and add some extra logic to handle attachments with the `attachmentType` property of `file`:
8484

8585
```js
8686
chatClient.on("chatMessageReceived", (e) => {
8787
console.log("Notification chatMessageReceived!");
88-
// check whether the notification is intended for the current thread
88+
// Check whether the notification is intended for the current thread
8989
if (threadIdInput.value != e.threadId) {
9090
return;
9191
}
@@ -101,7 +101,7 @@ async function renderReceivedMessage(event) {
101101
messages += `<div class="container lighter"> ${event.message} </div>`;
102102
messagesContainer.innerHTML = messages;
103103

104-
// get list of attachments and calls renderFileAttachments to construct a file attachment card
104+
// Get the list of attachments and calls renderFileAttachments to construct a file attachment card
105105
var attachmentHtml = event.attachments
106106
.filter(attachment => attachment.attachmentType === "file")
107107
.map(attachment => renderFileAttachments(attachment))
@@ -124,10 +124,10 @@ function renderFileAttachments(attachment) {
124124

125125
```
126126

127-
Let's make sure we add some CSS for the attachment card:
127+
Make sure you add some CSS for the attachment card:
128128

129129
```css
130-
/* let's make chat popup scrollable */
130+
/* Let's make the chat popup scrollable */
131131
.chat-popup {
132132

133133
...
@@ -193,11 +193,11 @@ Let's make sure we add some CSS for the attachment card:
193193

194194
```
195195

196-
That's all we need for handling file attachments. Next let's run the code.
196+
That's all you need for handling file attachments. Next, let's run the code.
197197

198-
## Run the code
198+
## Run the code
199199

200-
For Webpack, you can use the `webpack-dev-server` to build and run your app. Run the following command to bundle your application host on a local webserver:
200+
For Webpack, you can use the `webpack-dev-server` property to build and run your app. Run the following command to bundle your application host on a local web server:
201201

202202
```console
203203
npx webpack-dev-server --entry ./client.js --output bundle.js --debug --devtool inline-source-map
@@ -211,24 +211,23 @@ npm start
211211

212212
## File attachment demo
213213

214-
1. Open your browser and navigate to `http://localhost:8080/`. Enter the meeting URL and the thread ID.
214+
1. Open your browser and go to `http://localhost:8080/`. Enter the meeting URL and the thread ID.
215215

216-
2. Now let's send some file attachments from Teams client like this:
216+
1. Send some file attachments from the Teams client.
217217

218-
:::image type="content" source="./media/meeting-interop-features-file-attachment-1.png" alt-text="A screenshot of Teams client showing a sent message with three file attachments.":::
218+
:::image type="content" source="./media/meeting-interop-features-file-attachment-1.png" alt-text="Screenshot that shows the Teams client with a sent message with three file attachments.":::
219219

220-
3. Then you should see the new message being rendered along with file attachments:
221-
222-
:::image type="content" source="./media/meeting-interop-features-file-attachment-2.png" alt-text="A screenshot of sample app showing a received incoming message with three file attachments.":::
220+
1. You should see the new message being rendered along with file attachments.
223221

222+
:::image type="content" source="./media/meeting-interop-features-file-attachment-2.png" alt-text="Screenshot that shows a sample app with a received incoming message with three file attachments.":::
224223

225224
## Handle image attachments
226225

227-
Image attachments need to be treated differently than standard `file` attachments. Image attachments have the `attachmentType` of `image`, which requires the communication token to retrieve either the preview or full-size images.
226+
Image attachments need to be treated differently than standard `file` attachments. Image attachments have the `attachmentType` property of `image`, which requires the communication token to retrieve either the preview or full-size images.
228227

229-
Before continuing, complete the tutorial that demonstrates [how to enable inline image support in your chat app](../meeting-interop-features-inline-image.md). This tutorial describes how to fetch images that require a communication token in the request header. Upon receiving the image blob, we need to create an `ObjectUrl` that points to this blob. Then we inject this URL into the `src` attribute of each inline image.
228+
Before you continue, complete the tutorial that demonstrates [how to enable inline image support in your Chat app](../meeting-interop-features-inline-image.md). This tutorial describes how to fetch images that require a communication token in the request header. After you receive the image blob, you need to create an `ObjectUrl` property that points to this blob. Then you inject this URL into the `src` attribute of each inline image.
230229

231-
Now you're familiar with how inline images work, and it's easy to render image attachments just like a regular inline image.
230+
Now that you're familiar with how inline images work, you can render image attachments like a regular inline image.
232231

233232
First, inject an `image` tag into message content whenever there's an image attachment:
234233

@@ -244,18 +243,18 @@ async function renderReceivedMessage(event) {
244243
.join('');
245244
messagesContainer.innerHTML += imageAttachmentHtml;
246245

247-
// get list of attachments and calls renderFileAttachments to construct a file attachment card
246+
// Get a list of attachments and calls renderFileAttachments to construct a file attachment card
248247
var attachmentHtml = event.attachments
249248
.filter(attachment => attachment.attachmentType === "file")
250249
.map(attachment => renderFileAttachments(attachment))
251250
.join('');
252251
messagesContainer.innerHTML += attachmentHtml;
253252

254-
// filter out inline images from attchments
253+
// Filter out inline images from attachments
255254
const imageAttachments = event.attachments.filter((attachment) =>
256255
attachment.attachmentType === "image" && messages.includes(attachment.id));
257256

258-
// fetch and render preview images
257+
// Fetch and render preview images
259258
fetchPreviewImages(imageAttachments);
260259
}
261260

@@ -264,7 +263,7 @@ function renderImageAttachments(attachment) {
264263
}
265264
```
266265

267-
Now let's borrow `fetchPreviewImages()` from the [Tutorial: Enable Inline Image Support](../meeting-interop-features-inline-image.md), and use it as is without any changes:
266+
Now, let's borrow `fetchPreviewImages()` from the [Tutorial: Enable inline image support](../meeting-interop-features-inline-image.md) and use it as is without any changes:
268267

269268
```js
270269
function fetchPreviewImages(attachments) {
@@ -295,7 +294,8 @@ function fetchPreviewImages(attachments) {
295294
});
296295
}
297296
```
298-
This function needs a `tokenString` so we need a global copy initialized in `init()` as demonstrated in the following code snippet:
297+
298+
This function needs a `tokenString` property, so you need a global copy initialized in `init()`, as shown in the following code snippet:
299299

300300
```js
301301
var tokenString = '';
@@ -314,17 +314,16 @@ async function init() {
314314

315315
Now you have image attachment support. Continue to run the code and see it in action.
316316

317-
318317
## Image attachment demo
319318

320-
1. Send some image attachments from Teams client like this:
319+
1. Send some image attachments from the Teams client.
321320

322-
:::image type="content" source="./media/meeting-interop-features-file-attachment-3.png" alt-text="A screenshot of Teams client showing a send box with an image attachment uploaded.":::
321+
:::image type="content" source="./media/meeting-interop-features-file-attachment-3.png" alt-text="Screenshot that shows the Teams client showing a send box with an image attachment uploaded.":::
323322

324-
2. Upon sending the image attachment, notice that it becomes an inline image on the Teams client side:
323+
1. After you send the image attachment, notice that it becomes an inline image on the Teams client side.
325324

326-
:::image type="content" source="./media/meeting-interop-features-file-attachment-4.png" alt-text="A screenshot of Teams client showing a message with the image attachment sent to the other participant.":::
325+
:::image type="content" source="./media/meeting-interop-features-file-attachment-4.png" alt-text="Screenshot that shows the Teams client showing a message with the image attachment sent to the other participant.":::
327326

328-
3. Return to the sample app and make sure the same image is rendered:
327+
1. Return to the sample app and make sure the same image is rendered.
329328

330-
:::image type="content" source="./media/meeting-interop-features-file-attachment-5.png" alt-text="A screenshot of sample app showing an incoming message with one inline image rendered.":::
329+
:::image type="content" source="./media/meeting-interop-features-file-attachment-5.png" alt-text="Screenshot that shows a sample app showing an incoming message with one inline image rendered.":::

0 commit comments

Comments
 (0)