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
In this tutorial, you learn how to enable inline image support 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 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.
13
+
14
+
There are two parts in this tutorial, you learn what you need to do:
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)
18
+
19
+
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.
22
+
23
+
12
24
## Sample Code
25
+
13
26
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).
14
27
15
-
## Prerequisites
28
+
## Handle received inline images in new message event
29
+
30
+
In this section, we learn how we can render inline images embedded in the message content of new message received event.
31
+
32
+
### Prerequisites
16
33
17
34
* You've gone through the quickstart - [Join your chat app to a Teams meeting](../../../quickstarts/chat/meeting-interop.md).
18
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.
19
36
* You've set up a Teams meeting using your business account and have the meeting URL ready.
20
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).
21
38
22
-
## Goal
23
-
24
-
1. Be able to render preview images in the message thread
25
-
2. Be able to render full scale image upon click on preview images
26
-
27
-
## Handle inline images for new messages
28
39
29
40
30
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:
Now we've concluded all the changes we need to render inline images for messages coming from real time notifications.
302
310
303
311
304
-
## Run the code
312
+
###Run the code
305
313
306
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:
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:
314
322
315
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.":::
@@ -320,5 +328,146 @@ Then you should see the new message being rendered along with preview images:
320
328
321
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:
322
330
323
-
:::image type="content" source="./media/meeting-interop-features-inline-2.png" alt-text="A screenshot of sample app shown an overlay of a full scale image being presented.":::
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.":::
332
+
333
+
334
+
## Handle sending inline images in 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).
345
+
346
+
347
+
Let's take a look of the new API from `ChatThreadClient`:
348
+
349
+
```js
350
+
var imageAttachment =awaitchatThreadClient.uploadImage(blob, file.name, {
351
+
"onUploadProgress": reportProgressCallback
352
+
});
353
+
```
354
+
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:
358
+
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!
363
+
364
+
365
+
So let's begin to create a new file picker that accepts images like the following:
let uploadedImageModel =awaitchatThreadClient.uploadImage(blob, file.name, {
402
+
imageBytesLength:file.size
403
+
});
404
+
uploadedImageModels.push(uploadedImageModel);
405
+
}
406
+
```
407
+
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.
409
+
410
+
Lastly we need to modify the sendMessageButton event listener we created previously to attach images we just uploaded.
That's it, now let's run the code and see it in action.
448
+
449
+
### Run the code
450
+
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:
Open your browser and navigate to `http://localhost:8080/`. Noticing we have a new section in the send box to attach images:
460
+
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.":::
462
+
463
+
Then we can select images we wanted to attach:
464
+
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.":::
466
+
467
+
:::image type="content" source="./media/meeting-interop-features-inline-7.png" alt-text="A screenshot of the sample app showing 2 images attached.":::
468
+
469
+
The Teams user should now receive the image we just sent out when they click on send button:
470
+
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.":::
324
472
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.":::
# Tutorial: Enable inline image support in your Chat app
16
16
17
-
The Chat SDK works seamlessly with Microsoft Teams in the context of a meeting. Specifically, Chat SDK provides a solution to receive inline images sent by users from Microsoft Teams. Currently this feature is only available in the Chat SDK for JavaScript and C#.
18
-
19
-
## Add inline image support
20
-
21
-
Inline images are images that are copied and pasted directly into the send box of the Teams client. For images that were uploaded using the **Upload from this device** menu or via drag-and-drop, such as images dragged directly to the send box in Teams, see [Tutorial: Enable file attachment support in your Chat app](./meeting-interop-features-file-attachment.md) to enable file attachment support as part of the file sharing feature. For images, see the [Handle image attachments](./meeting-interop-features-file-attachment.md#handle-image-attachments) section. 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.
22
-
23
-
The Chat SDK for JavaScript provides `previewUrl` and `url` for each inline image. Some GIF images fetched from `previewUrl` might not be animated, and a static preview image may be returned instead. Developers need to use the `url` if the intention is to fetch animated images only.
24
-
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.
25
18
26
19
::: zone pivot="programming-language-javascript"
27
-
[!INCLUDE [Teams Inline Image Interop with JavaScript SDK](./includes/meeting-interop-features-inline-image-javascript.md)]
20
+
[!INCLUDE [Teams Inline Image Interop with JavaScript SDK](./includes/meeting-interop-features-inline-image-receiving-javascript.md)]
28
21
::: zone-end
29
22
30
23
::: zone pivot="programming-language-csharp"
31
-
[!INCLUDE [Teams Inline Image Interop with C# SDK](./includes/meeting-interop-features-inline-image-csharp.md)]
24
+
[!INCLUDE [Teams Inline Image Interop with C# SDK](./includes/meeting-interop-features-inline-image-receiving-csharp.md)]
0 commit comments