Skip to content

Commit 49a1b3b

Browse files
committed
edit pass: two-chat-sdk-tutorials
1 parent d66f875 commit 49a1b3b

File tree

2 files changed

+64
-76
lines changed

2 files changed

+64
-76
lines changed

articles/communication-services/tutorials/chat-interop/includes/meeting-interop-features-inline-image-receiving-javascript.md

Lines changed: 58 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,39 @@ ms.topic: include
77
ms.service: azure-communication-services
88
---
99

10-
In this tutorial, you learn how to enable inline image support using the Azure Communication Services Chat SDK for JavaScript.
10+
In this tutorial, you learn how to enable inline image support by using the Azure Communication Services Chat SDK for JavaScript.
1111

12-
Inline images are images that are copied and pasted directly into the send box of the Teams client. For images uploaded via the "Upload from this device" menu or via drag-and-drop, such as images dragged directly to the send box in Teams, you need to refer to [this tutorial](../meeting-interop-features-file-attachment.md) as the part of the file sharing feature. (See the section "Handling Image Attachment.") To copy an image, the Teams user can either use their operating system's context menu to copy the image file and then paste it into the send box of their Teams client or use keyboard shortcuts.
12+
Inline images are images that are copied and pasted directly into the send box of the Teams client. For images uploaded via the **Upload from this device** menu or via drag-and-drop, such as images dragged directly to the send box in Teams, you need to refer to [this tutorial](../meeting-interop-features-file-attachment.md) as the part of the file-sharing feature. (See the section "Handle Image Attachments.")
1313

14-
There are two parts in this tutorial, you learn what you need to do:
14+
To copy an image, Teams users have two options:
1515

16-
- [when receiving an inline image](#handle-received-inline-images-in-new-message-event)
17-
- [when sending out an inline image](#handle-sending-inline-images-in-new-message-request)
16+
- Use their operating system's context menu to copy the image file and then paste it into the send box of their Teams client.
17+
- Use keyboard shortcuts.
1818

19+
In this tutorial, you learn what you need to do when you:
1920

20-
> [!NOTE]
21-
> The ability to send inline images is currently available in public preview and it's only available for JavaScript only. For receiving inline images, it's currently general available and available for both JavaScript and C# in a Teams interoperability chat.
21+
- [Receive an inline image](#handle-received-inline-images-in-new-message-event)
22+
- [Send out an inline image](#handle-sending-inline-images-in-new-message-request)
2223

24+
> [!NOTE]
25+
> The ability to send inline images is currently available in public preview. It's only available for JavaScript. For receiving inline images, it's currently generally available. It's available for both JavaScript and C# in a Teams interoperability chat.
2326
24-
## Sample Code
27+
## Sample code
2528

2629
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).
2730

28-
## Handle received inline images in new message event
31+
## Prerequisites
2932

30-
In this section, we learn how we can render inline images embedded in the message content of new message received event.
33+
* Review the quickstart [Join your Chat app to a Teams meeting](../../../quickstarts/chat/meeting-interop.md).
34+
* 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.
35+
* Set up a Teams meeting by using your business account and have the meeting URL ready.
36+
* Use the Chat SDK for JavaScript (@azure/communication-chat) 1.4.0 or latest. For more information, see [Azure Communication Chat client library for JavaScript](https://www.npmjs.com/package/@azure/communication-chat).
3137

32-
### Prerequisites
38+
## Handle received inline images in a new message event
3339

34-
* You've gone through the quickstart - [Join your chat app to a Teams meeting](../../../quickstarts/chat/meeting-interop.md).
35-
* 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.
36-
* You've set up a Teams meeting using your business account and have the meeting URL ready.
37-
* You're using the Chat SDK for JavaScript (@azure/communication-chat) 1.4.0 or latest. See [here](https://www.npmjs.com/package/@azure/communication-chat).
40+
In this section, you learn how you can render inline images embedded in the message content of a new message received event.
3841

39-
40-
41-
In the [quickstart](../../../quickstarts/chat/meeting-interop.md), we've created an event handler for `chatMessageReceived` event, which would be trigger when we receive a new message from the Teams user. We have also appended incoming message content to `messageContainer` directly upon receiving the `chatMessageReceived` event from the `chatClient` like this:
42+
In the [quickstart](../../../quickstarts/chat/meeting-interop.md), you created an event handler for the `chatMessageReceived` event, which is triggered when you receive a new message from the Teams user. You also append incoming message content to `messageContainer` directly upon receiving the `chatMessageReceived` event from the `chatClient`, like this:
4243

4344
```js
4445
chatClient.on("chatMessageReceived", (e) => {
@@ -62,7 +63,7 @@ async function renderReceivedMessage(message) {
6263
messagesContainer.innerHTML = messages;
6364
}
6465
```
65-
From incoming event of type `ChatMessageReceivedEvent`, there's a property named `attachments`, which contains information about inline image, and it's all we need to render inline images in our UI:
66+
From the incoming event of type `ChatMessageReceivedEvent`, a property named `attachments` contains information about the inline image. It's all you need to render inline images in your UI:
6667

6768
```js
6869
export interface ChatMessageReceivedEvent extends BaseChatMessageEvent {
@@ -98,7 +99,7 @@ export interface ChatAttachment {
9899
export type ChatAttachmentType = "image" | "unknown";
99100
```
100101

101-
Now let's go back to the previous code to add some extra logic like the following code snippets:
102+
Now let's go back to the previous code to add some extra logic like the following code snippets:
102103

103104
```js
104105
chatClient.on("chatMessageReceived", (e) => {
@@ -178,10 +179,9 @@ async function fetchPreviewImages(attachments) {
178179
}
179180
```
180181

181-
Noticing in this example, we've created two helper functions - `fetchPreviewImages` and `setImgHandler` - where the first one fetches preview image directly from the `previewURL` provided in each `ChatAttachment` object with an auth header. Similarly, we set up a `onclick` event for each image in the function `setImgHandler`, and in the event handler, we fetch a full scale image from property `url` from the `ChatAttachment` object with an auth header.
182-
182+
In this example, you created two helper functions, `fetchPreviewImages` and `setImgHandler`. The first one fetches the preview image directly from the `previewURL` provided in each `ChatAttachment` object with an auth header. Similarly, you set up a `onclick` event for each image in the function `setImgHandler`. In the event handler, you fetch a full-scale image from property `url` from the `ChatAttachment` object with an auth header.
183183

184-
Another thing we need to do is to expose token on to the global level since we need to construct an auth header with it. So we need to modify the following code:
184+
Now you need to expose the token on to the global level because you need to construct an auth header with it. You need to modify the following code:
185185

186186
```js
187187
// new variable for token string
@@ -205,7 +205,7 @@ async function init() {
205205

206206
```
207207

208-
To show full scale image in an overlay, we need to add a new component as well:
208+
To show the full-scale image in an overlay, you also need to add a new component:
209209

210210
```html
211211

@@ -266,7 +266,7 @@ With some CSS:
266266
}
267267
```
268268

269-
Now we have an overlay set up, it's time to work on the logic to render full scale images. Recall that we've created an `onClick` event handler to call a function `fetchFullScaleImage`:
269+
Now that you have an overlay set up, it's time to work on the logic to render full-scale images. Recall that you created an `onClick` event handler to call a function `fetchFullScaleImage`:
270270

271271
```js
272272

@@ -297,7 +297,7 @@ function fetchFullScaleImage(e, imageAttachments) {
297297

298298
```
299299

300-
One last thing we want to add is the ability to dismiss the overlay when clicking on the image:
300+
One last thing you want to add is the ability to dismiss the overlay when the image is clicked:
301301

302302
```js
303303
loadingImageOverlay.addEventListener('click', () => {
@@ -306,77 +306,66 @@ loadingImageOverlay.addEventListener('click', () => {
306306

307307
```
308308

309-
Now we've concluded all the changes we need to render inline images for messages coming from real time notifications.
309+
Now, you've made all the changes you need to render inline images for messages that come from real-time notifications.
310310

311+
### Run the code
311312

312-
### Run the code
313-
314-
Webpack users 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:
313+
Webpack users can use `webpack-dev-server` to build and run your app. Run the following command to bundle your application host on a local webserver:
315314

316315
```console
317316
npx webpack-dev-server --entry ./client.js --output bundle.js --debug --devtool inline-source-map
318317
```
319318

320319
### Demo
321-
Open your browser and navigate to `http://localhost:8080/`. Enter the meeting URL and the thread ID. Send some inline images from Teams client like this:
320+
Open your browser and go to `http://localhost:8080/`. Enter the meeting URL and the thread ID. Send some inline images from the Teams client.
322321

323-
:::image type="content" source="./media/meeting-interop-features-inline-3.png" alt-text="A screenshot of Teams client shown a sent message reads: Here are some ideas, let me know what you think! The message also contains two inline images of room interior mockups.":::
322+
:::image type="content" source="./media/meeting-interop-features-inline-3.png" alt-text="Screenshot that shows a Teams client with a sent message that reads: Here are some ideas, let me know what you think! The message also contains two inline images of room interior mockups.":::
324323

325-
Then you should see the new message being rendered along with preview images:
324+
Then you should see the new message rendered along with preview images.
326325

327-
:::image type="content" source="./media/meeting-interop-features-inline-1.png" alt-text="A screenshot of sample app shown an incoming message with inline images being presented.":::
326+
:::image type="content" source="./media/meeting-interop-features-inline-1.png" alt-text="Screenshot that shows a sample app with an incoming message with inline images.":::
328327

329-
Upon clicking the preview image by the Azure Communication Services user, an overlay would be shown with the full scale image sent by the Teams user:
328+
After the Azure Communication Services user selects the preview image, an overlay appears with the full-scale image sent by the Teams user.
330329

331-
:::image type="content" source="./media/meeting-interop-features-inline-2.png" alt-text="A screenshot of sample app showing an overlay of a full scale image being presented.":::
330+
:::image type="content" source="./media/meeting-interop-features-inline-2.png" alt-text="Screenshot that shows a sample app with an overlay of a full-scale image.":::
332331

333-
334-
## Handle sending inline images in new message request
332+
## Handle sending inline images in a new message request
335333

336334
[!INCLUDE [Public Preview Notice](../../../includes/public-preview-include.md)]
337335

338-
In addition to handle messages with inline images, Chat SDK for JavaScript also provides a solution to allow the Communication User to send inline images to the Microsoft Teams user in an interoperability chat.
339-
340-
341-
### Prerequisites
342-
343-
* You've gone through the previous section for [handling-received-inline-images-in-new-message-event](#handle-received-inline-images-in-new-message-event)
344-
* You're using the Chat SDK for JavaScript (@azure/communication-chat) 1.6.0-beta.1 or latest. See [here](https://www.npmjs.com/package/@azure/communication-chat).
336+
In addition to handling messages with inline images, the Chat SDK for JavaScript also provides a solution to allow the communication user to send inline images to the Microsoft Teams user in an interoperability chat.
345337

346-
347-
Let's take a look of the new API from `ChatThreadClient`:
338+
Let's take a look at the new API from `ChatThreadClient`:
348339

349340
```js
350341
var imageAttachment = await chatThreadClient.uploadImage(blob, file.name, {
351342
"onUploadProgress": reportProgressCallback
352343
});
353344
```
354345

355-
Noticing the API takes in an image blob, file name string, and a function callback that reports upload progress.
356-
357-
Therefore, to send an image to other chat participant, we need to:
346+
The API takes in an image blob, file name string, and a function callback that reports upload progress.
358347

359-
1. Upload the image via `uploadImage` API from `ChatThreadClient`, save the returned object to somewhere
360-
2. Compose the message content and set attachment to the returned object we have saved in previous step
361-
3. Send the new message via `sendMessage` API from `ChatThreadClient`
362-
4. Done!
348+
To send an image to other chat participant, you need to:
363349

350+
1. Upload the image via the `uploadImage` API from `ChatThreadClient`, and save the returned object.
351+
1. Compose the message content and set an attachment to the returned object you saved in the previous step.
352+
1. Send the new message via the `sendMessage` API from `ChatThreadClient`.
364353

365-
So let's begin to create a new file picker that accepts images like the following:
354+
Let's create a new file picker that accepts images:
366355

367356
```html
368357
<label for="myfile">Attach images:</label>
369358
<input id="upload" type="file" id="myfile" name="myfile" accept="image/*" multiple>
370359
<input style="display: none;" id="upload-result"></input>
371360
```
372361

373-
Next we need to set up an event licenser for when there's a state change:
362+
Now set up an event licenser for when there's a state change:
374363

375364
```js
376365
document.getElementById("upload").addEventListener("change", uploadImages);
377366
```
378367

379-
Here we need to create a new function for when state changes:
368+
You need to create a new function for when state changes:
380369

381370
```js
382371
var uploadedImageModels = [];
@@ -405,9 +394,9 @@ async function uploadImage(file) {
405394
}
406395
```
407396

408-
Noticing in this example, we have created a `FileReader` to read each image as `base64` encoded images, then create a `Blob` before calling the ChatSDK API to upload them. Also notice how we created a global `uploadedImageModels` to save the data models of uploaded images from the ChatSDK.
397+
In this example, you created a `FileReader` to read each image as `base64`-encoded images, then create a `Blob` before calling the ChatSDK API to upload them. You created a global `uploadedImageModels` to save the data models of uploaded images from the Chat SDK.
409398

410-
Lastly we need to modify the sendMessageButton event listener we created previously to attach images we just uploaded.
399+
Lastly, you need to modify the `sendMessageButton` event listener you created previously to attach the images you uploaded.
411400

412401
```js
413402
sendMessageButton.addEventListener("click", async () => {
@@ -444,30 +433,30 @@ sendMessageButton.addEventListener("click", async () => {
444433

445434
```
446435

447-
That's it, now let's run the code and see it in action.
436+
That's it. Now let's run the code and see it in action.
448437

449438
### Run the code
450439

451-
Webpack users 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:
440+
Webpack users can use `webpack-dev-server` to build and run your app. Run the following command to bundle your application host on a local webserver:
452441

453442
```console
454443
npx webpack-dev-server --entry ./client.js --output bundle.js --debug --devtool inline-source-map
455444
```
456445

457446
### Demo
458447

459-
Open your browser and navigate to `http://localhost:8080/`. Noticing we have a new section in the send box to attach images:
448+
Open your browser and go to `http://localhost:8080/`. You have a new section in the send box to attach images.
460449

461-
:::image type="content" source="./media/meeting-interop-features-inline-5.png" alt-text="A screenshot of sample app with a newly add section to attach images.":::
450+
:::image type="content" source="./media/meeting-interop-features-inline-5.png" alt-text="Screenshot that shows a sample app with a newly added section to attach images.":::
462451

463-
Then we can select images we wanted to attach:
452+
Next, you can select the images you want to attach.
464453

465-
:::image type="content" source="./media/meeting-interop-features-inline-6.png" alt-text="A screenshot of a file picker that shows a list of images user can attach to their message.":::
454+
:::image type="content" source="./media/meeting-interop-features-inline-6.png" alt-text="Screenshot that shows a file picker with a list of images users can attach to their messages.":::
466455

467-
:::image type="content" source="./media/meeting-interop-features-inline-7.png" alt-text="A screenshot of the sample app showing 2 images attached.":::
456+
:::image type="content" source="./media/meeting-interop-features-inline-7.png" alt-text="Screenshot that shows the sample app with two images attached.":::
468457

469-
The Teams user should now receive the image we just sent out when they click on send button:
458+
The Teams user should now receive the image you just sent out when they select **Send**.
470459

471-
:::image type="content" source="./media/meeting-interop-features-inline-8.png" alt-text="A screenshot of the sample app showing a sent message with 2 images embedded.":::
460+
:::image type="content" source="./media/meeting-interop-features-inline-8.png" alt-text="Screenshot that shows the sample app with a sent message with two embedded images.":::
472461

473-
:::image type="content" source="./media/meeting-interop-features-inline-9.png" alt-text="A screenshot of Teams client showing a received message with 2 image embedded.":::
462+
:::image type="content" source="./media/meeting-interop-features-inline-9.png" alt-text="Screenshot that shows the Teams client with a received message with two embedded images.":::
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Enable Inline Image Support in your Chat app
2+
title: Enable inline image support in your Chat app
33
titleSuffix: An Azure Communication Services quickstart
44
description: This tutorial describes how to enable inline image interoperability with the Azure Communication Chat SDK.
55
author: jpeng-ms
@@ -14,19 +14,18 @@ zone_pivot_groups: acs-js-csharp
1414

1515
# Tutorial: Enable inline image support in your Chat app
1616

17-
The Chat SDK is designed to work with Microsoft Teams seamlessly. Specifically, Chat SDK provides a solution to receive inline images and send inline images to users from Microsoft Teams.
17+
The Chat SDK is designed to work with Microsoft Teams seamlessly. Specifically, Chat SDK provides a solution to receive inline images and send inline images to users from Microsoft Teams.
1818

1919
::: zone pivot="programming-language-javascript"
2020
[!INCLUDE [Teams Inline Image Interop with JavaScript SDK](./includes/meeting-interop-features-inline-image-receiving-javascript.md)]
2121
::: zone-end
2222

23-
::: zone pivot="programming-language-csharp"
23+
::: zone pivot="programming-language-csharp"
2424
[!INCLUDE [Teams Inline Image Interop with C# SDK](./includes/meeting-interop-features-inline-image-receiving-csharp.md)]
2525
::: zone-end
2626

27-
2827
## Next steps
2928

30-
- Learn more about other [supported interoperability features](../../concepts/interop/guest/capabilities.md)
31-
- Check out our [chat hero sample](../../samples/chat-hero-sample.md)
32-
- Learn more about [how chat works](../../concepts/chat/concepts.md)
29+
- Learn more about other [supported interoperability features](../../concepts/interop/guest/capabilities.md).
30+
- Check out our [Chat hero sample](../../samples/chat-hero-sample.md).
31+
- Learn more about [how Chat works](../../concepts/chat/concepts.md).

0 commit comments

Comments
 (0)