microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
feature/oauthflow-fixes

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/samples/CompatBot/Program.cs

60lines · modecode

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