Search code examples
androidmicrosoft-graph-apiazure-communication-servicesazure-android-sdk

User presence/status in Azure communication service (Teams)


I am building an Android app using Azure communication service SDK. I can make a call, receive a call, everything seems to work fine except one thing: the status of my user is always offline. Is there a way to set the status of the user to online/away/... using the communication service SDK?

Just to be clear: I am not trying to retrieve the status of a user, but to set it up. Right now my user is considered "online" but appears "offline" on the Teams app.

At that point, even if there's an endpoint to query via an API to set it up I'd be okay with that, any solution would work.


Solution

  • Note that: Azure Communication Services (ACS) does not provide a direct API or SDK feature to set the presence status (online, away, etc.) of a user. Check this SO Thread by rocky and MsDoc

    Hence, alternatively you can make use of Microsoft Graph API like below:

    • You need to grant Presence.ReadWrite or Presence.ReadWrite.All API permission.

    To get the user's presence status, use the below query:

    GET https://graph.microsoft.com/v1.0/users/UserID/presence
    

    enter image description here

    To set the user's presence status, use the below query:

    POST https://graph.microsoft.com/v1.0/users/UserID/presence/setPresence
    
    {
      "sessionId": "The ID of the application's presence session",
      "availability": "Available",
      "activity": "Available",
      "expirationDuration": "PT1H"
    }
    

    enter image description here

    The user's presence status is set to available:

    enter image description here

    You can refer this blog and integrate with Azure Event Grid by Manish Saluja.

    Reference:

    presence: setPresence - Microsoft Graph v1.0 | Microsoft