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/chat-interop/includes/meeting-interop-features-inline-image-receiving-javascript.md
+58-69Lines changed: 58 additions & 69 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,38 +7,39 @@ ms.topic: include
7
7
ms.service: azure-communication-services
8
8
---
9
9
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.
11
11
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 filesharing 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.")
13
13
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:
15
15
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.
18
18
19
+
In this tutorial, you learn what you need to do when you:
19
20
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 inlineimages, 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)
22
23
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.
23
26
24
-
## Sample Code
27
+
## Sample code
25
28
26
29
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).
27
30
28
-
## Handle received inline images in new message event
31
+
## Prerequisites
29
32
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).
31
37
32
-
### Prerequisites
38
+
##Handle received inline images in a new message event
33
39
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.
38
41
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:
42
43
43
44
```js
44
45
chatClient.on("chatMessageReceived", (e) => {
@@ -62,7 +63,7 @@ async function renderReceivedMessage(message) {
62
63
messagesContainer.innerHTML= messages;
63
64
}
64
65
```
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:
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:
102
103
103
104
```js
104
105
chatClient.on("chatMessageReceived", (e) => {
@@ -178,10 +179,9 @@ async function fetchPreviewImages(attachments) {
178
179
}
179
180
```
180
181
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.
183
183
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:
185
185
186
186
```js
187
187
// new variable for token string
@@ -205,7 +205,7 @@ async function init() {
205
205
206
206
```
207
207
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:
209
209
210
210
```html
211
211
@@ -266,7 +266,7 @@ With some CSS:
266
266
}
267
267
```
268
268
269
-
Now we have an overlay set up, it's time to work on the logic to render fullscale 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`:
270
270
271
271
```js
272
272
@@ -297,7 +297,7 @@ function fetchFullScaleImage(e, imageAttachments) {
297
297
298
298
```
299
299
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:
Now we've concluded all the changes we need to render inline images for messages coming from realtime notifications.
309
+
Now, you've made all the changes you need to render inline images for messages that come from real-time notifications.
310
310
311
+
### Run the code
311
312
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:
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.
322
321
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.":::
324
323
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.
326
325
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.":::
328
327
329
-
Upon clicking the preview image by the Azure Communication Services user, an overlay would be shown with the fullscale 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.
330
329
331
-
:::image type="content" source="./media/meeting-interop-features-inline-2.png" alt-text="A screenshot of sample app showing an overlay of a fullscale 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.":::
332
331
333
-
334
-
## Handle sending inline images in new message request
332
+
## Handle sending inline images in a new message request
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.
345
337
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`:
348
339
349
340
```js
350
341
var imageAttachment =awaitchatThreadClient.uploadImage(blob, file.name, {
351
342
"onUploadProgress": reportProgressCallback
352
343
});
353
344
```
354
345
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.
358
347
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:
363
349
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`.
364
353
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:
Here we need to create a new function for when state changes:
368
+
You need to create a new function for when state changes:
380
369
381
370
```js
382
371
var uploadedImageModels = [];
@@ -405,9 +394,9 @@ async function uploadImage(file) {
405
394
}
406
395
```
407
396
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.
409
398
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.
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.
448
437
449
438
### Run the code
450
439
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:
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.
460
449
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.":::
462
451
463
-
Then we can select images we wanted to attach:
452
+
Next, you can select the images you want to attach.
464
453
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.":::
466
455
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.":::
468
457
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**.
470
459
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.":::
472
461
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.":::
# Tutorial: Enable inline image support in your Chat app
16
16
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.
18
18
19
19
::: zone pivot="programming-language-javascript"
20
20
[!INCLUDE [Teams Inline Image Interop with JavaScript SDK](./includes/meeting-interop-features-inline-image-receiving-javascript.md)]
21
21
::: zone-end
22
22
23
-
::: zone pivot="programming-language-csharp"
23
+
::: zone pivot="programming-language-csharp"
24
24
[!INCLUDE [Teams Inline Image Interop with C# SDK](./includes/meeting-interop-features-inline-image-receiving-csharp.md)]
25
25
::: zone-end
26
26
27
-
28
27
## Next steps
29
28
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