Search code examples
c#asp.netazureazure-communication-services

How can I attach a file in an Azure communication service chat?


I develop chat application using azure communication service chat. For that I follow https://github.com/Azure-Samples/communication-services-web-chat-hero this example and its work. Now I am try to send attachment in this chat but I am not able to find any salutation.

Is it possible to add attachment?


Solution

  • Currently attaching files to chat messages is not natively supported by the Azure Communication Services JavaScript Chat SDK.

    I would recommend filing a feature request here for built-in support: https://github.com/Azure/azure-sdk-for-js/issues/new?assignees=&labels=&template=feature_request.md

    Conceptually this is totally possible however, if we take the example of embedding a video inside a chat message:

    1. The web client sending the video would need to first upload the video to a storage space you own. This could be to your server or a third party storage solution such as Azure Blob Storage.
    2. The chat message would need to include a placeholder value that indicates there should be a video file here e.g. Take a look at this video: {{video src=VIDEO_SRC}}.
    3. Web clients receiving chat messages would need to first parse through the message and look for special indicators (in our case this would be {{video src=VIDEO_SRC}}). If one is found, the message would need to be specially constructed to support a video. In this case the message html may end up something like:
      <div>
        Take a look at this video:
        <video src=VIDEO_SRC />
      </div>
      

    NOTE: This is just one, trivial implementation of how it could be possible to implement attachments in a chat message. This does not take into account security concerns with allowing attachments to chat messages and validation should be performed on message content before being placed into a chat message.