microsoft/teams.net

Public

mirrored from https://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.0.0-preview.6

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Samples/Samples.Graph/Program.cs

57lines · modecode

1using Microsoft.Teams.Apps;
2using Microsoft.Teams.Apps.Activities;
3using Microsoft.Teams.Apps.Extensions;
4using Microsoft.Teams.Plugins.AspNetCore.Extensions;
5
6var builder = WebApplication.CreateBuilder(args);
7
8var appBuilder = App.Builder()
9 .AddLogger(level: Microsoft.Teams.Common.Logging.LogLevel.Debug)
10 // The name of the auth connection to use.
11 // It should be the same as the OAuth connection name defined in the Azure Bot configuration.
12 .AddOAuth("graph");
13
14builder.AddTeams(appBuilder);
15
16var app = builder.Build();
17var teams = app.UseTeams();
18
19teams.OnMessage("/signout", async context =>
20{
21 if (!context.IsSignedIn)
22 {
23 await context.Send("you are not signed in!");
24 return;
25 }
26
27 await context.SignOut(); // call `SignOut()` for your auth connection...
28 await context.Send("you have been signed out!");
29});
30
31teams.OnMessage(async context =>
32{
33 if (!context.IsSignedIn)
34 {
35 await context.SignIn(new SignInOptions()
36 {
37 // Customize the OAuth card text (only applies to OAuth flow, not SSO)
38 OAuthCardText = "Sign in to your account",
39 SignInButtonText = "Sign In"
40 }); // call `SignIn() for your auth connection...
41
42 return;
43 }
44
45 var me = await context.UserGraph.Me.GetAsync();
46 await context.Send($"user '{me!.DisplayName}' is already signed in!");
47});
48
49teams.OnSignIn(async (_, @event) => {
50 var token = @event.Token;
51 var context = @event.Context;
52
53 var me = await context.UserGraph.Me.GetAsync();
54 await context.Send($"user \"{me!.DisplayName}\" signed in. Here's the token: {token.Token}");
55});
56
57app.Run();