microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/sub-pr-338

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/samples/CompatBot/Program.cs

58lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Azure.Monitor.OpenTelemetry.AspNetCore;
5using CompatBot;
6
7using Microsoft.Bot.Builder;
8using Microsoft.Bot.Builder.Integration.AspNet.Core;
9using Microsoft.Teams.Bot.Core;
10using Microsoft.Teams.Bot.Compat;
11using Microsoft.Bot.Schema;
12
13// using Microsoft.Bot.Connector.Authentication;
14
15WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
16builder.Services.AddOpenTelemetry().UseAzureMonitor();
17builder.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
26MemoryStorage storage = new();
27ConversationState conversationState = new(storage);
28builder.Services.AddSingleton(conversationState);
29builder.Services.AddTransient<IBot, EchoBot>();
30
31WebApplication app = builder.Build();
32
33CompatAdapter compatAdapter = (CompatAdapter)app.Services.GetRequiredService<IBotFrameworkHttpAdapter>();
34compatAdapter.Use(new MyCompatMiddleware());
35compatAdapter.Use(new MyCompatMiddleware());
36
37app.MapPost("/api/messages", async (IBotFrameworkHttpAdapter adapter, IBot bot, HttpRequest request, HttpResponse response, CancellationToken ct) =>
38 await adapter.ProcessAsync(request, response, bot, ct));
39
40app.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
58app.Run();
59