Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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<BotFrameworkHttpAdapter> logger)
: base(configuration, logger)
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<IBotFrameworkHttpAdapter> logger)
: base(auth, logger)
{
OnTurnError = async (turnContext, exception) =>
{
Expand Down
72 changes: 57 additions & 15 deletions extensibility/agents-sdk/relay-bot/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Startup>();
}
options.SerializerSettings.MaxDepth = HttpHelper.BotMessageSerializerSettings.MaxDepth;
});


builder.Services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFrameworkAuthentication>();

// Create the Bot Adapter with error handling enabled.
builder.Services.AddSingleton<IBotFrameworkHttpAdapter, AdapterWithErrorHandler>();

// Create the bot as a transient. In this case the ASP Controller is expecting an IBot.
builder.Services.AddSingleton<IBot, RelayBot>();

// Create the singleton instance of BotService from appsettings
var botService = new BotService();
builder.Configuration.Bind("BotService", (object)botService);
builder.Services.AddSingleton<IBotService>(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();
14 changes: 7 additions & 7 deletions extensibility/agents-sdk/relay-bot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand All @@ -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

Expand Down
8 changes: 4 additions & 4 deletions extensibility/agents-sdk/relay-bot/SampleBot.csproj
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.5.1" />
<PackageReference Include="Microsoft.Bot.Connector.DirectLine" Version="3.0.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="10.0.5" />
<PackageReference Include="Microsoft.Bot.Builder.Integration.AspNet.Core" Version="4.23.1" />
<PackageReference Include="Microsoft.Bot.Connector.DirectLine" Version="3.0.2" />
</ItemGroup>

<ItemGroup>
Expand Down
64 changes: 0 additions & 64 deletions extensibility/agents-sdk/relay-bot/Startup.cs

This file was deleted.

5 changes: 5 additions & 0 deletions extensibility/agents-sdk/relay-bot/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
{
// Configuration for Azure bot service
"MicrosoftAppType": "",
"MicrosoftAppId": "",
"MicrosoftAppPassword": "",
"MicrosoftAppTenantId": "",

// Configuration for MCS Bot
"BotService": {
"BotName": "",
"BotId": "",
Expand Down