-
Notifications
You must be signed in to change notification settings - Fork 16
Sample PA Bot with advanced DI, including multi hosting #308
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next/core
Are you sure you want to change the base?
Conversation
Added a new sample bot project, PABot, demonstrating Teams SSO authentication and Microsoft Graph integration. The sample includes dialogs for OAuth login, user info/photo display, and logout, and is integrated into the solution. No changes to existing source code outside of solution/project structure.
Replaces default Bot Framework auth/adapter with a custom MSAL-based compatibility adapter using Microsoft.Identity.Web. Adds InitCompatAdapter.cs and PACustomAuthHandler.cs for token acquisition and HTTP client setup. Introduces a simple EchoBot for testing. Updates Program.cs to use the new adapter. Cleans up appsettings.json and adds launchSettings.TEMPLATE.json for local dev configuration. No functional changes to project references.
- Changed authorization policy from "TeamsInABS" to "TeamsInAPX" in InitCompatAdapter.cs. - Updated ConversationClient to use "MsalAPX" and scopeApx; TeamsApiClient now uses "MsalABS" and scopeAbs. - Added SsoBot.cs, a new bot that echoes messages and handles user token status and sign-in links. - Added a commented-out registration for SsoBot in Program.cs.
Introduces the CompatProactive sample project demonstrating proactive messaging using the Teams Bot Compat Layer and .NET 8.0. Adds a ProactiveWorker background service, configures logging, and updates the solution file. Also includes minor logging and code safety improvements in SsoBot.cs.
- Introduce extensible, keyed multi-instance support for compat adapter registration via new AddCompatAdapter overloads - Add CompatAdapterOptions and KeyedBotAuthenticationHandler for per-instance configuration and token acquisition - Refactor registration logic to use library-based, idempotent, and testable approach; remove old manual logic - Support custom auth handler injection per instance - Preserve backward compatibility for non-keyed scenarios - Add comprehensive unit tests for all registration paths and options - Improve documentation and add settings.local.json for test permissions
…to next/core-pa-compat-multihost
singhk97
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm with a few changes
| sp.GetRequiredService<TeamsBotApplication>()); | ||
|
|
||
| services.AddSingleton<CompatBotAdapter>(); | ||
| services.AddKeyedSingleton<CompatBotAdapter>("AzureAd", (sp, _) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This distinction between CompatBotAdapter and CompatAdapter is adding unnecessary complexity. PR to fix it: #307
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's merge 307 first, and then we can refactor this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merged it
| /// <returns>The same <see cref="IServiceCollection"/> instance for method chaining.</returns> | ||
| /// <exception cref="ArgumentNullException">Thrown when <paramref name="services"/> is null.</exception> | ||
| /// <exception cref="ArgumentException">Thrown when <paramref name="key"/> is null or whitespace.</exception> | ||
| public static IServiceCollection AddCompatAdapter( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really add a CompatAdapter and relies on the dev to create the CompatAdapter. I like this approach since it works well with the AdapterWithErrorHandler pattern used in BF. But it should be called smth like AddCompatAdapterCore and description should be updated.
|
|
||
| builder.Services.AddCustomCompatAdapter(); | ||
|
|
||
| builder.Services.AddKeyedSingleton<IBotFrameworkHttpAdapter>("RidoABSOne", (sp, keyName) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AddCustomCompatAdapter doesn't add a CompatAdapter, it adds the underlying components. Name should be updated to reflect that.
This pull request introduces two new sample bots,
CompatProactiveandPABot, to the solution. These samples demonstrate proactive messaging and authentication scenarios using the compatibility layer. The changes include new project files, bot implementations, dialog classes, and configuration updates to support these samples.New Sample Bots and Related Components:
CompatProactivesample project, which demonstrates sending proactive messages using the compatibility adapter. This includes the project file (CompatProactive.csproj), a background worker (ProactiveWorker.cs), a simple program entry point (Program.cs), and logging configuration (appsettings.json). [1] [2] [3] [4]PABotsample project, which showcases authentication, SSO, and Teams bot scenarios. This includes:AdapterWithErrorHandler.cs)DialogBot,EchoBot,SsoBot, andTeamsBot[1] [2] [3] [4]LogoutDialog.cs)Solution Configuration:
core.slnx) to include the newCompatProactiveandPABotsample projects, and fixed the ordering and grouping of test and source projects. [1] [2]