Skip to content

Commit 108986c

Browse files
singhvikra-microadileiclaude
authored
Fix RelayBot: Upgrade .Net target and Remove Obsolete BotFramework Adapter. (#475)
* Upgrade .Net target and Remove Obsolete BotFramework Adapter. * update newtonsoft version * add missing tenant property in appsettings.json * upgrade the program file with top level statements. * update README.md for .net 10 * Update deprecated notice: clarify archived Bot Framework SDK, fix Copilot Studio naming Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: adilei <adileibowiz@microsoft.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ee75f83 commit 108986c

File tree

6 files changed

+77
-94
lines changed

6 files changed

+77
-94
lines changed

extensibility/agents-sdk/relay-bot/AdapterWithErrorHandler.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// Licensed under the MIT License.
33

44
using Microsoft.Bot.Builder.Integration.AspNet.Core;
5-
using Microsoft.Extensions.Configuration;
5+
using Microsoft.Bot.Connector.Authentication;
66
using Microsoft.Extensions.Logging;
77

88
namespace Microsoft.PowerVirtualAgents.Samples.RelayBotSample
99
{
10-
public class AdapterWithErrorHandler : BotFrameworkHttpAdapter
10+
public class AdapterWithErrorHandler : CloudAdapter
1111
{
12-
public AdapterWithErrorHandler(IConfiguration configuration, ILogger<BotFrameworkHttpAdapter> logger)
13-
: base(configuration, logger)
12+
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<IBotFrameworkHttpAdapter> logger)
13+
: base(auth, logger)
1414
{
1515
OnTurnError = async (turnContext, exception) =>
1616
{
Lines changed: 57 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,62 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4-
using Microsoft.AspNetCore;
5-
using Microsoft.AspNetCore.Hosting;
4+
using Microsoft.AspNetCore.Builder;
5+
using Microsoft.Bot.Builder;
6+
using Microsoft.Bot.Builder.Integration.AspNet.Core;
7+
using Microsoft.Bot.Connector.Authentication;
8+
using Microsoft.Extensions.Configuration;
9+
using Microsoft.Extensions.DependencyInjection;
10+
using Microsoft.Extensions.Hosting;
11+
using Microsoft.PowerVirtualAgents.Samples.RelayBotSample;
12+
using Microsoft.PowerVirtualAgents.Samples.RelayBotSample.Bots;
613

7-
namespace Microsoft.PowerVirtualAgents.Samples.RelayBotSample
8-
{
9-
public class Program
14+
var builder = WebApplication.CreateBuilder(args);
15+
16+
//---- Configure services ----
17+
builder.Services.AddHttpClient();
18+
builder.Services.AddControllers()
19+
.AddNewtonsoftJson(options =>
1020
{
11-
public static void Main(string[] args)
12-
{
13-
CreateWebHostBuilder(args).Build().Run();
14-
}
15-
16-
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
17-
WebHost.CreateDefaultBuilder(args)
18-
.UseStartup<Startup>();
19-
}
21+
options.SerializerSettings.MaxDepth = HttpHelper.BotMessageSerializerSettings.MaxDepth;
22+
});
23+
24+
25+
builder.Services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFrameworkAuthentication>();
26+
27+
// Create the Bot Adapter with error handling enabled.
28+
builder.Services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();
29+
30+
// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
31+
builder.Services.AddSingleton<IBot, RelayBot>();
32+
33+
// Create the singleton instance of BotService from appsettings
34+
var botService = new BotService();
35+
builder.Configuration.Bind("BotService", (object)botService);
36+
builder.Services.AddSingleton<IBotService>(botService);
37+
38+
// Create the singleton instance of ConversationPool from appsettings
39+
var conversationManager = new ConversationManager();
40+
builder.Configuration.Bind("ConversationPool", conversationManager);
41+
builder.Services.AddSingleton(conversationManager);
42+
43+
var app = builder.Build();
44+
45+
//--- - Configure the HTTP request pipeline ----
46+
if (app.Environment.IsDevelopment())
47+
{
48+
app.UseDeveloperExceptionPage();
49+
}
50+
else
51+
{
52+
app.UseHsts();
2053
}
54+
55+
app.UseDefaultFiles()
56+
.UseStaticFiles()
57+
.UseWebSockets()
58+
.UseRouting();
59+
60+
app.MapControllers();
61+
62+
app.Run();

extensibility/agents-sdk/relay-bot/README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ Deprecated
1010
{: .label .label-red }
1111

1212
{: .caution }
13-
> This sample is deprecated and will be replaced with a modernized M365 Agents SDK sample.
13+
> This sample uses the archived Bot Framework SDK (`Microsoft.Bot.Builder`). It will be replaced with an M365 Agents SDK implementation.
1414
15-
Sample of connecting Bot Framework v4 bot to a Power Virtual Agent bot.
15+
Sample of connecting an Azure Bot Service bot to a Copilot Studio agent using the Direct Line API.
1616

17-
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
17+
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
1818

1919
## Prerequisites
2020

21-
- [.NET Core SDK](https://dotnet.microsoft.com/download) version 2.1
21+
- [.NET SDK](https://dotnet.microsoft.com/download) version 10.0
2222

2323
```bash
2424
# determine dotnet version
@@ -30,10 +30,10 @@ This bot has been created based on [Bot Framework](https://dev.botframework.com)
3030
- Clone the repository
3131

3232
```bash
33-
git clone https://github.com/microsoft/PowerVirtualAgentsSample.git
33+
git clone https://github.com/microsoft/CopilotStudioSamples.git
3434
```
3535

36-
- In a terminal, navigate to `BYOBSample/`
36+
- In a terminal, navigate to `extensibility/agents-sdk/relay-bot`
3737
- Update file appsettings.json with your Power Virtual Agent bot id, tenant id, bot name and other settings.
3838

3939
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)
5454

5555
- Launch Visual Studio
5656
- File -> Open -> Project/Solution
57-
- Navigate to `BYOBSample/` folder
57+
- Navigate to `extensibility/agents-sdk/relay-bot` folder
5858
- Select `SampleBot.csproj` file
5959
- Press `F5` to run the project
6060

extensibility/agents-sdk/relay-bot/SampleBot.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.1</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.AspNetCore.App" />
10-
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.5.1" />
11-
<PackageReference Include="Microsoft.Bot.Connector.DirectLine" Version="3.0.2" />
9+
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.5" />
10+
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.23.1" />
11+
<PackageReference Include="Microsoft.Bot.Connector.DirectLine" Version="3.0.2" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

extensibility/agents-sdk/relay-bot/Startup.cs

Lines changed: 0 additions & 64 deletions
This file was deleted.

extensibility/agents-sdk/relay-bot/appsettings.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
{
2+
// Configuration for Azure bot service
3+
"MicrosoftAppType": "",
24
"MicrosoftAppId": "",
35
"MicrosoftAppPassword": "",
6+
"MicrosoftAppTenantId": "",
7+
8+
// Configuration for MCS Bot
49
"BotService": {
510
"BotName": "",
611
"BotId": "",

0 commit comments

Comments
 (0)