microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
b4fb261ef78741a3ac023785e13ad411a0d6e23d

Branches

Tags

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

Clone

HTTPS

Download ZIP

Samples/Samples.Graph/Program.cs

59lines · modecode

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