Questo esempio in C# mostra l'uso dell'API Graph Get presence per Teams

URL

https://graph.microsoft.com/v1.0/me/presence
per leggere lo stato della presenza dell'utente corrente

C#

using Azure.Identity;
using Microsoft.Graph;

var tenantId = "<tenantId>";
var clientId = "<clientId>";
var userName = "<userName>";
var password = "<password>";

var scopes = new[] { "Presence.Read" };

var options = new UsernamePasswordCredentialOptions
{
    AuthorityHost = AzureAuthorityHosts.AzurePublicCloud,
    // IsUnsafeSupportLoggingEnabled = true,
};

var userNamePasswordCredential = new UsernamePasswordCredential(
    userName, password, tenantId, clientId, options);

var graphClient = new GraphServiceClient(userNamePasswordCredential, scopes);

while (true)
{
    var mypresence = await graphClient.Me.Presence.GetAsync();

    Console.WriteLine(mypresence?.Availability + " - " + mypresence?.Activity);

    System.Threading.Thread.Sleep(5000);
}
package necessari

PowerShell

dotnet add package Microsoft.Graph --version 5.31.0
dotnet add package Azure.Identity
Valori possibili per Availability
  • Available
  • AvailableIdle,
  • Away
  • BeRightBack
  • Busy
  • BusyIdle
  • DoNotDisturb
  • Offline
  • PresenceUnknown
mentre per Activity (informazioni aggiuntive)
  • Available,
  • Away
  • BeRightBack
  • Busy
  • DoNotDisturb
  • InACall
  • InAConferenceCall
  • Inactive
  • InAMeeting
  • Offline
  • OffWork
  • OutOfOffice
  • PresenceUnknown
  • Presenting
  • UrgentInterruptionsOnly
Tags:
Teams2 C#236 Esempi225
Potrebbe interessarti anche: