microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
core/samples/CompatBot/Program.cs
58lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Azure.Monitor.OpenTelemetry.AspNetCore; |
| 5 | using CompatBot; |
| 6 | |
| 7 | using Microsoft.Bot.Builder; |
| 8 | using Microsoft.Bot.Builder.Integration.AspNet.Core; |
| 9 | using Microsoft.Teams.Bot.Core; |
| 10 | using Microsoft.Teams.Bot.Compat; |
| 11 | using Microsoft.Bot.Schema; |
| 12 | |
| 13 | // using Microsoft.Bot.Connector.Authentication; |
| 14 | |
| 15 | WebApplicationBuilder builder = WebApplication.CreateBuilder(args); |
| 16 | builder.Services.AddOpenTelemetry().UseAzureMonitor(); |
| 17 | builder.AddCompatAdapter(); |
| 18 | |
| 19 | //builder.Services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFrameworkAuthentication>(); |
| 20 | //builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(provider => |
| 21 | // new CloudAdapter( |
| 22 | // provider.GetRequiredService<BotFrameworkAuthentication>(), |
| 23 | // provider.GetRequiredService<ILogger<CloudAdapter>>())); |
| 24 | |
| 25 | |
| 26 | MemoryStorage storage = new(); |
| 27 | ConversationState conversationState = new(storage); |
| 28 | builder.Services.AddSingleton(conversationState); |
| 29 | builder.Services.AddTransient<IBot, EchoBot>(); |
| 30 | |
| 31 | WebApplication app = builder.Build(); |
| 32 | |
| 33 | CompatAdapter compatAdapter = (CompatAdapter)app.Services.GetRequiredService<IBotFrameworkHttpAdapter>(); |
| 34 | compatAdapter.Use(new MyCompatMiddleware()); |
| 35 | compatAdapter.Use(new MyCompatMiddleware()); |
| 36 | |
| 37 | app.MapPost("/api/messages", async (IBotFrameworkHttpAdapter adapter, IBot bot, HttpRequest request, HttpResponse response, CancellationToken ct) => |
| 38 | await adapter.ProcessAsync(request, response, bot, ct)); |
| 39 | |
| 40 | app.MapGet("/api/notify/{cid}", async (IBotFrameworkHttpAdapter adapter, string cid, CancellationToken ct) => |
| 41 | { |
| 42 | Activity proactive = new() |
| 43 | { |
| 44 | Conversation = new() { Id = cid }, |
| 45 | ServiceUrl = "https://smba.trafficmanager.net/teams" |
| 46 | }; |
| 47 | await ((BotAdapter)adapter).ContinueConversationAsync( |
| 48 | string.Empty, |
| 49 | proactive.GetConversationReference(), |
| 50 | async (turnContext, ct) => |
| 51 | { |
| 52 | await turnContext.SendActivityAsync( |
| 53 | MessageFactory.Text($"Proactive. <br/> SDK `{BotApplication.Version}` at {DateTime.Now:T}"), ct); |
| 54 | }, |
| 55 | ct); |
| 56 | }); |
| 57 | |
| 58 | app.Run(); |
| 59 | |