// Copyright (c) Microsoft Corporation. // Licensed under the MIT License. using CompatBot; using Microsoft.Bot.Builder; using Microsoft.Bot.Builder.Integration.AspNet.Core; using Microsoft.Bot.Schema; using Microsoft.Teams.Apps.BotBuilder; using Microsoft.Teams.Core; // using Microsoft.Bot.Connector.Authentication; WebApplicationBuilder builder = WebApplication.CreateBuilder(args); builder.AddTeamsBotFrameworkHttpAdapter(); //builder.Services.AddSingleton(); //builder.Services.AddSingleton(provider => // new CloudAdapter( // provider.GetRequiredService(), // provider.GetRequiredService>())); MemoryStorage storage = new(); ConversationState conversationState = new(storage); builder.Services.AddSingleton(conversationState); builder.Services.AddTransient(); WebApplication app = builder.Build(); TeamsBotFrameworkHttpAdapter compatAdapter = (TeamsBotFrameworkHttpAdapter)app.Services.GetRequiredService(); compatAdapter.Use(new MyCompatMiddleware()); compatAdapter.Use(new MyCompatMiddleware()); compatAdapter.OnTurnError = async (turnContext, exception) => { await turnContext.SendActivityAsync(MessageFactory.Text("Oops, something went wrong! Please try again later.")); }; app.MapPost("/api/messages", async (IBotFrameworkHttpAdapter adapter, IBot bot, HttpRequest request, HttpResponse response, CancellationToken ct) => await adapter.ProcessAsync(request, response, bot, ct)).RequireAuthorization(); app.MapGet("/api/notify/{cid}", async (IBotFrameworkHttpAdapter adapter, string cid, CancellationToken ct) => { Activity proactive = new() { Conversation = new() { Id = cid }, ServiceUrl = "https://smba.trafficmanager.net/teams" }; await ((BotAdapter)adapter).ContinueConversationAsync( string.Empty, proactive.GetConversationReference(), async (turnContext, ct) => { await turnContext.SendActivityAsync( MessageFactory.Text($"Proactive.
SDK `{BotApplication.Version}` at {DateTime.Now:T}"), ct); }, ct); }); app.Run();