microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
copilot/move-activity-classes-to-core-again

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/samples/CompatBot/Program.cs

55lines · 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.Bot.Core;
10using Microsoft.Bot.Core.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
33
34app.MapPost("/api/messages", async (IBotFrameworkHttpAdapter adapter, IBot bot, HttpRequest request, HttpResponse response, CancellationToken ct) =>
35 await adapter.ProcessAsync(request, response, bot, ct));
36
37app.MapGet("/api/notify/{cid}", async (IBotFrameworkHttpAdapter adapter, string cid, CancellationToken ct) =>
38{
39 Activity proactive = new()
40 {
41 Conversation = new() { Id = cid },
42 ServiceUrl = "https://smba.trafficmanager.net/teams"
43 };
44 await ((CompatAdapter)adapter).ContinueConversationAsync(
45 string.Empty,
46 proactive.GetConversationReference(),
47 async (turnContext, ct) =>
48 {
49 await turnContext.SendActivityAsync(
50 MessageFactory.Text($"Proactive. <br/> SDK `{BotApplication.Version}` at {DateTime.Now:T}"), ct);
51 },
52 ct);
53});
54
55app.Run();
56