microsoft/teams.net

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
next/core-claude-agents

Branches

Tags

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

Clone

HTTPS

Download ZIP

core/samples/PABot/Program.cs

45lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4using Microsoft.Bot.Builder;
5using Microsoft.Bot.Builder.Integration.AspNet.Core;
6using Microsoft.Teams.Bot.Core;
7using PABot;
8using PABot.Bots;
9using PABot.Dialogs;
10
11WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
12
13// Register TeamsBotApplication and all dependencies (uses MsalBot and MsalAgent configuration sections)
14builder.Services.AddTeamsBotApplications();
15
16// Register adapter using the TeamsBotApplication
17builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp =>
18{
19 return new AdapterWithErrorHandler(
20 sp.GetRequiredService<BotApplication>(),
21 sp.GetRequiredService<IHttpContextAccessor>(),
22 sp.GetRequiredService<IConfiguration>(),
23 sp.GetRequiredService<ILogger<IBotFrameworkHttpAdapter>>(),
24 sp.GetRequiredService<IStorage>(),
25 sp.GetRequiredService<ConversationState>());
26});
27
28// Register bot state and dialog
29builder.Services.AddSingleton<IStorage, MemoryStorage>();
30builder.Services.AddSingleton<UserState>();
31builder.Services.AddSingleton<ConversationState>();
32builder.Services.AddSingleton<MainDialog>();
33
34// Register bot (pick between TeamsBot & EchoBot)
35// builder.Services.AddTransient<IBot, TeamsBot<MainDialog>>();
36// builder.Services.AddTransient<IBot, EchoBot>();
37builder.Services.AddTransient<IBot, SsoBot>();
38
39WebApplication app = builder.Build();
40
41// Map endpoint with BotAdapter authorization policy
42app.MapPost("/api/messages", (HttpRequest request, HttpResponse response, IBot bot, CancellationToken ct, IBotFrameworkHttpAdapter adapter) =>
43 adapter.ProcessAsync(request, response, bot, ct)).RequireAuthorization("BotAdapter");
44
45app.Run();
46