diff --git a/extensibility/agents-sdk/relay-bot/AdapterWithErrorHandler.cs b/extensibility/agents-sdk/relay-bot/AdapterWithErrorHandler.cs index 57a27b15..f9741868 100644 --- a/extensibility/agents-sdk/relay-bot/AdapterWithErrorHandler.cs +++ b/extensibility/agents-sdk/relay-bot/AdapterWithErrorHandler.cs @@ -2,15 +2,15 @@ // Licensed under the MIT License. using Microsoft.Bot.Builder.Integration.AspNet.Core; -using Microsoft.Extensions.Configuration; +using Microsoft.Bot.Connector.Authentication; using Microsoft.Extensions.Logging; namespace Microsoft.PowerVirtualAgents.Samples.RelayBotSample { - public class AdapterWithErrorHandler : BotFrameworkHttpAdapter + public class AdapterWithErrorHandler : CloudAdapter { - public AdapterWithErrorHandler(IConfiguration configuration, ILogger logger) - : base(configuration, logger) + public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger logger) + : base(auth, logger) { OnTurnError = async (turnContext, exception) => { diff --git a/extensibility/agents-sdk/relay-bot/Program.cs b/extensibility/agents-sdk/relay-bot/Program.cs index 5ed15a40..17ddf2a8 100644 --- a/extensibility/agents-sdk/relay-bot/Program.cs +++ b/extensibility/agents-sdk/relay-bot/Program.cs @@ -1,20 +1,62 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. +// Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. -using Microsoft.AspNetCore; -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Builder; +using Microsoft.Bot.Builder; +using Microsoft.Bot.Builder.Integration.AspNet.Core; +using Microsoft.Bot.Connector.Authentication; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.PowerVirtualAgents.Samples.RelayBotSample; +using Microsoft.PowerVirtualAgents.Samples.RelayBotSample.Bots; -namespace Microsoft.PowerVirtualAgents.Samples.RelayBotSample -{ - public class Program +var builder = WebApplication.CreateBuilder(args); + +//---- Configure services ---- +builder.Services.AddHttpClient(); +builder.Services.AddControllers() + .AddNewtonsoftJson(options => { - public static void Main(string[] args) - { - CreateWebHostBuilder(args).Build().Run(); - } - - public static IWebHostBuilder CreateWebHostBuilder(string[] args) => - WebHost.CreateDefaultBuilder(args) - .UseStartup(); - } + options.SerializerSettings.MaxDepth = HttpHelper.BotMessageSerializerSettings.MaxDepth; + }); + + +builder.Services.AddSingleton(); + +// Create the Bot Adapter with error handling enabled. +builder.Services.AddSingleton(); + +// Create the bot as a transient. In this case the ASP Controller is expecting an IBot. +builder.Services.AddSingleton(); + +// Create the singleton instance of BotService from appsettings +var botService = new BotService(); +builder.Configuration.Bind("BotService", (object)botService); +builder.Services.AddSingleton(botService); + +// Create the singleton instance of ConversationPool from appsettings +var conversationManager = new ConversationManager(); +builder.Configuration.Bind("ConversationPool", conversationManager); +builder.Services.AddSingleton(conversationManager); + +var app = builder.Build(); + +//--- - Configure the HTTP request pipeline ---- +if (app.Environment.IsDevelopment()) +{ + app.UseDeveloperExceptionPage(); +} +else +{ + app.UseHsts(); } + +app.UseDefaultFiles() + .UseStaticFiles() + .UseWebSockets() + .UseRouting(); + +app.MapControllers(); + +app.Run(); diff --git a/extensibility/agents-sdk/relay-bot/README.md b/extensibility/agents-sdk/relay-bot/README.md index 69641a2c..a1092559 100644 --- a/extensibility/agents-sdk/relay-bot/README.md +++ b/extensibility/agents-sdk/relay-bot/README.md @@ -10,15 +10,15 @@ Deprecated {: .label .label-red } {: .caution } -> This sample is deprecated and will be replaced with a modernized M365 Agents SDK sample. +> This sample uses the archived Bot Framework SDK (`Microsoft.Bot.Builder`). It will be replaced with an M365 Agents SDK implementation. -Sample of connecting Bot Framework v4 bot to a Power Virtual Agent bot. +Sample of connecting an Azure Bot Service bot to a Copilot Studio agent using the Direct Line API. -This bot has been created based on [Bot Framework](https://dev.botframework.com), it shows how to create an Azure Bot Service bot that connects to Power Virtual Agents bot +This bot has been created based on [Bot Framework](https://dev.botframework.com), it shows how to create an Azure Bot Service bot that connects to a Copilot Studio agent ## Prerequisites -- [.NET Core SDK](https://dotnet.microsoft.com/download) version 2.1 +- [.NET SDK](https://dotnet.microsoft.com/download) version 10.0 ```bash # determine dotnet version @@ -30,10 +30,10 @@ This bot has been created based on [Bot Framework](https://dev.botframework.com) - Clone the repository ```bash - git clone https://github.com/microsoft/PowerVirtualAgentsSample.git + git clone https://github.com/microsoft/CopilotStudioSamples.git ``` -- In a terminal, navigate to `BYOBSample/` +- In a terminal, navigate to `extensibility/agents-sdk/relay-bot` - Update file appsettings.json with your Power Virtual Agent bot id, tenant id, bot name and other settings. To retrieve your bot's bot ID and tenant ID, click on left side pane's ***Manage***, click ***Channels*** and click on the Azure Bot Service channel that you need to connect to. @@ -54,7 +54,7 @@ This bot has been created based on [Bot Framework](https://dev.botframework.com) - Launch Visual Studio - File -> Open -> Project/Solution - - Navigate to `BYOBSample/` folder + - Navigate to `extensibility/agents-sdk/relay-bot` folder - Select `SampleBot.csproj` file - Press `F5` to run the project diff --git a/extensibility/agents-sdk/relay-bot/SampleBot.csproj b/extensibility/agents-sdk/relay-bot/SampleBot.csproj index cefada66..41a17caf 100644 --- a/extensibility/agents-sdk/relay-bot/SampleBot.csproj +++ b/extensibility/agents-sdk/relay-bot/SampleBot.csproj @@ -1,14 +1,14 @@ - netcoreapp2.1 + net10.0 latest - - - + + + diff --git a/extensibility/agents-sdk/relay-bot/Startup.cs b/extensibility/agents-sdk/relay-bot/Startup.cs deleted file mode 100644 index c23b24c0..00000000 --- a/extensibility/agents-sdk/relay-bot/Startup.cs +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Bot.Builder; -using Microsoft.Bot.Builder.Integration.AspNet.Core; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.PowerVirtualAgents.Samples.RelayBotSample.Bots; - -namespace Microsoft.PowerVirtualAgents.Samples.RelayBotSample -{ - public class Startup - { - public Startup(IConfiguration configuration) - { - Configuration = configuration; - } - - public IConfiguration Configuration { get; } - - // This method gets called by the runtime. Use this method to add services to the container. - public void ConfigureServices(IServiceCollection services) - { - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); - - // Create the Bot Framework Adapter with error handling enabled. - services.AddSingleton(); - - // Create the bot as a transient. In this case the ASP Controller is expecting an IBot. - services.AddSingleton(); - - // Create the singleton instance of BotService from appsettings - var botService = new BotService(); - Configuration.Bind("BotService", (object)botService); - services.AddSingleton(botService); - - // Create the singleton instance of ConversationPool from appsettings - var conversationManager = new ConversationManager(); - Configuration.Bind("ConversationPool", conversationManager); - services.AddSingleton(conversationManager); - } - - // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) - { - if (env.IsDevelopment()) - { - app.UseDeveloperExceptionPage(); - } - else - { - app.UseHsts(); - } - - app.UseDefaultFiles(); - app.UseStaticFiles(); - - app.UseMvc(); - } - } -} diff --git a/extensibility/agents-sdk/relay-bot/appsettings.json b/extensibility/agents-sdk/relay-bot/appsettings.json index 5d1da922..d366a013 100644 --- a/extensibility/agents-sdk/relay-bot/appsettings.json +++ b/extensibility/agents-sdk/relay-bot/appsettings.json @@ -1,6 +1,11 @@ { + // Configuration for Azure bot service + "MicrosoftAppType": "", "MicrosoftAppId": "", "MicrosoftAppPassword": "", + "MicrosoftAppTenantId": "", + + // Configuration for MCS Bot "BotService": { "BotName": "", "BotId": "",