microsoft/teams.net
Publicmirrored from https://github.com/microsoft/teams.netAvailable
core/samples/CachingAuthTokens/Program.cs
29lines · modecode
| 1 | using System.Diagnostics; |
| 2 | using Microsoft.Teams.Apps; |
| 3 | using Microsoft.Teams.Apps.Handlers; |
| 4 | |
| 5 | var builder = WebApplication.CreateSlimBuilder(args); |
| 6 | builder.Services |
| 7 | .AddTeamsBotApplication() |
| 8 | .AddStackExchangeRedisCache(options => |
| 9 | { |
| 10 | options.Configuration = builder.Configuration.GetConnectionString("Redis"); // requires a Redis instance, for local testing you can use Docker: `docker run -p 6379:6379 redis` |
| 11 | }); |
| 12 | |
| 13 | var app = builder.Build(); |
| 14 | |
| 15 | var bot = app.UseTeamsBotApplication(); |
| 16 | |
| 17 | bot.OnMessage(async (ctx, ct) => |
| 18 | { |
| 19 | var clock = Stopwatch.StartNew(); |
| 20 | var text = ctx.Activity.Text; |
| 21 | var replyText = $"Echo: {text}"; |
| 22 | await ctx.SendActivityAsync(replyText, ct); |
| 23 | |
| 24 | var diagnosticInfo = $"sdk version: {TeamsBotApplication.Version} os: {Environment.OSVersion}"; |
| 25 | diagnosticInfo += $" reply latency: {clock.Elapsed.TotalMilliseconds}ms"; |
| 26 | await ctx.SendActivityAsync(diagnosticInfo, ct); |
| 27 | }); |
| 28 | |
| 29 | app.Run(); |
| 30 | |