How to implement real time chat in WPF application using ACS

Jakub Pernica 145 Reputation points


I'm trying to figure out the Azure Communication Services - Chat functionality in my .NET 7 WPF application. I created a simple window (see picture):

User's image

I'm able to get user identity and access token, create new thread and invite other participants, but now the main problem is, how do I make the chat itself responsive? I can fetch all messages manually using AsyncPageable <ChatMessage> allMessages = chatThreadClient.GetMessagesAsync(); but how would I implement it in such a way the messages are updated automatically or with some kind of event?


Azure Communication Services
Azure Communication Services
An Azure communication platform for deploying applications across devices and platforms.
488 questions
{count} votes

Accepted answer
  1. VenkateshDodda-MSFT 11,846 Reputation points Microsoft Employee

    @Jakub Pernica Thanks for your patience on this. I have checked with internal team and sharing the below.

    As mentioned in the documentation or as you pointed out earlier currently real time notifications are not available for .Net.

    Alternatively, you can achieve this, by running a background thread that will keep calling this function GetMessagesAsync() with a time offset to fetch the messages that have been sent in the past 5-10s.

    The other option is to by listening to Event Grid events and route those events to your application about the chat threads events. This is mentioned more here Chat concepts in Azure Communication Services - An Azure Communication Services concept document | Microsoft Learn.

    Since you have listening to specific event type you will receive notification form all the other threads as well you need to filter them depending on the customer thread.

    You can refer to this sample .Net WinForms wherein timer trigger keeps calling the chatThreadClient.GetMessagesAsync() function for updates.

    Feel free to reach back to me if you have any further questions on this.

0 additional answers

Sort by: Most helpful