Leggere lo stato della presenza in Teams
Questo esempio in C# mostra l'uso dell'API Graph Get presence per Teams
per leggere lo stato della presenza dell'utente corrente
package necessari
Valori possibili per Availability
URL
https://graph.microsoft.com/v1.0/me/presence
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);
}
PowerShell
dotnet add package Microsoft.Graph --version 5.31.0
dotnet add package Azure.Identity
- Available
- AvailableIdle,
- Away
- BeRightBack
- Busy
- BusyIdle
- DoNotDisturb
- Offline
- PresenceUnknown
- Available,
- Away
- BeRightBack
- Busy
- DoNotDisturb
- InACall
- InAConferenceCall
- Inactive
- InAMeeting
- Offline
- OffWork
- OutOfOffice
- PresenceUnknown
- Presenting
- UrgentInterruptionsOnly