microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next/oauth-card-null-ref-bug

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/samples/CompatBot/Program.cs

57lines · modecode

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