microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Samples/Samples.Auth/Program.cs
36lines · modecode
| 1 | using Microsoft.Teams.Apps; |
| 2 | using Microsoft.Teams.Apps.Activities; |
| 3 | using Microsoft.Teams.Apps.Extensions; |
| 4 | using Microsoft.Teams.Plugins.AspNetCore.Extensions; |
| 5 | |
| 6 | var builder = WebApplication.CreateBuilder(args); |
| 7 | builder.AddTeams(App.Builder().AddLogger(level: Microsoft.Teams.Common.Logging.LogLevel.Debug)); |
| 8 | |
| 9 | var app = builder.Build(); |
| 10 | var teams = app.UseTeams(); |
| 11 | |
| 12 | teams.OnMessage("/signout", async context => |
| 13 | { |
| 14 | if (!context.IsSignedIn) |
| 15 | { |
| 16 | await context.Send("you are not signed in!"); |
| 17 | return; |
| 18 | } |
| 19 | |
| 20 | await context.SignOut(); |
| 21 | await context.Send("you have been signed out!"); |
| 22 | }); |
| 23 | |
| 24 | teams.OnMessage(async context => |
| 25 | { |
| 26 | if (!context.IsSignedIn) |
| 27 | { |
| 28 | await context.SignIn(); |
| 29 | return; |
| 30 | } |
| 31 | |
| 32 | var me = await context.UserGraph.Me.GetAsync(); |
| 33 | await context.Send($"user '{me!.DisplayName}' is signed in!"); |
| 34 | }); |
| 35 | |
| 36 | app.Run(); |