Skip to content

Commit

Permalink
refactor: update teamsAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
xzf0587 committed Dec 11, 2024
1 parent af47bc3 commit 1453452
Show file tree
Hide file tree
Showing 18 changed files with 66 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Schema;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}
{
public class AdapterWithErrorHandler : CloudAdapter
public class AdapterWithErrorHandler : TeamsAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<CloudAdapter> logger)
: base(auth, logger)
public AdapterWithErrorHandler(IConfiguration auth, ILogger<TeamsAdapter> logger)
: base(auth, null, logger)
{
OnTurnError = async (turnContext, exception) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}.Controllers
{
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly CloudAdapter Adapter;
private readonly TeamsAdapter Adapter;
private readonly IBot Bot;
public BotController(CloudAdapter adapter, IBot bot)
public BotController(TeamsAdapter adapter, IBot bot)
{
Adapter = adapter;
Bot = bot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ builder.Services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFramew
// Create the Cloud Adapter with error handling enabled.
// Note: some classes expect a BotAdapter and some expect a BotFrameworkHttpAdapter, so
// register the same adapter instance for both types.
builder.Services.AddSingleton<CloudAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<TeamsAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<TeamsAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<TeamsAdapter>());

builder.Services.AddSingleton<IStorage, MemoryStorage>();
{{#useOpenAI}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Schema;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}
{
public class AdapterWithErrorHandler : CloudAdapter
public class AdapterWithErrorHandler : TeamsAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<CloudAdapter> logger)
: base(auth, logger)
public AdapterWithErrorHandler(IConfiguration auth, ILogger<TeamsAdapter> logger)
: base(auth, null, logger)
{
OnTurnError = async (turnContext, exception) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}.Controllers
{
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly CloudAdapter Adapter;
private readonly TeamsAdapter Adapter;
private readonly IBot Bot;
public BotController(CloudAdapter adapter, IBot bot)
public BotController(TeamsAdapter adapter, IBot bot)
{
Adapter = adapter;
Bot = bot;
Expand Down
6 changes: 3 additions & 3 deletions templates/csharp/custom-copilot-assistant-new/Program.cs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ builder.Services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFramew
// Create the Cloud Adapter with error handling enabled.
// Note: some classes expect a BotAdapter and some expect a BotFrameworkHttpAdapter, so
// register the same adapter instance for both types.
builder.Services.AddSingleton<CloudAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<TeamsAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<TeamsAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<TeamsAdapter>());

builder.Services.AddSingleton<IStorage, MemoryStorage>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Schema;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}
{
public class AdapterWithErrorHandler : CloudAdapter
public class AdapterWithErrorHandler : TeamsAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<CloudAdapter> logger)
: base(auth, logger)
public AdapterWithErrorHandler(IConfiguration auth, ILogger<TeamsAdapter> logger)
: base(auth, null, logger)
{
OnTurnError = async (turnContext, exception) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}.Controllers
{
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly CloudAdapter Adapter;
private readonly TeamsAdapter Adapter;
private readonly IBot Bot;
public BotController(CloudAdapter adapter, IBot bot)
public BotController(TeamsAdapter adapter, IBot bot)
{
Adapter = adapter;
Bot = bot;
Expand Down
6 changes: 3 additions & 3 deletions templates/csharp/custom-copilot-basic/Program.cs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ builder.Services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFramew
// Create the Cloud Adapter with error handling enabled.
// Note: some classes expect a BotAdapter and some expect a BotFrameworkHttpAdapter, so
// register the same adapter instance for both types.
builder.Services.AddSingleton<CloudAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<TeamsAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<TeamsAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<TeamsAdapter>());

builder.Services.AddSingleton<IStorage, MemoryStorage>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Schema;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}
{
public class AdapterWithErrorHandler : CloudAdapter
public class AdapterWithErrorHandler : TeamsAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<CloudAdapter> logger)
: base(auth, logger)
public AdapterWithErrorHandler(IConfiguration auth, ILogger<TeamsAdapter> logger)
: base(auth, null, logger)
{
OnTurnError = async (turnContext, exception) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}.Controllers
{
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly CloudAdapter Adapter;
private readonly TeamsAdapter Adapter;
private readonly IBot Bot;
public BotController(CloudAdapter adapter, IBot bot)
public BotController(TeamsAdapter adapter, IBot bot)
{
Adapter = adapter;
Bot = bot;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ builder.Services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFramew
// Create the Cloud Adapter with error handling enabled.
// Note: some classes expect a BotAdapter and some expect a BotFrameworkHttpAdapter, so
// register the same adapter instance for both types.
builder.Services.AddSingleton<CloudAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<TeamsAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<TeamsAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<TeamsAdapter>());

builder.Services.AddSingleton<IStorage, MemoryStorage>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Schema;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}
{
public class AdapterWithErrorHandler : CloudAdapter
public class AdapterWithErrorHandler : TeamsAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<CloudAdapter> logger)
: base(auth, logger)
public AdapterWithErrorHandler(IConfiguration auth, ILogger<TeamsAdapter> logger)
: base(auth, null, logger)
{
OnTurnError = async (turnContext, exception) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}.Controllers
{
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly CloudAdapter Adapter;
private readonly TeamsAdapter Adapter;
private readonly IBot Bot;
public BotController(CloudAdapter adapter, IBot bot)
public BotController(TeamsAdapter adapter, IBot bot)
{
Adapter = adapter;
Bot = bot;
Expand Down
6 changes: 3 additions & 3 deletions templates/csharp/custom-copilot-rag-custom-api/Program.cs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ builder.Services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFramew
// Create the Cloud Adapter with error handling enabled.
// Note: some classes expect a BotAdapter and some expect a BotFrameworkHttpAdapter, so
// register the same adapter instance for both types.
builder.Services.AddSingleton<CloudAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<TeamsAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<TeamsAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<TeamsAdapter>());

builder.Services.AddSingleton<IStorage, MemoryStorage>();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Connector.Authentication;
using Microsoft.Bot.Builder.TraceExtensions;
using Microsoft.Bot.Schema;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}
{
public class AdapterWithErrorHandler : CloudAdapter
public class AdapterWithErrorHandler : TeamsAdapter
{
public AdapterWithErrorHandler(BotFrameworkAuthentication auth, ILogger<CloudAdapter> logger)
: base(auth, logger)
public AdapterWithErrorHandler(IConfiguration auth, ILogger<TeamsAdapter> logger)
: base(auth, null, logger)
{
OnTurnError = async (turnContext, exception) =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Bot.Builder;
using Microsoft.Bot.Builder.Integration.AspNet.Core;
using Microsoft.Teams.AI;

namespace {{SafeProjectName}}.Controllers
{
[Route("api/messages")]
[ApiController]
public class BotController : ControllerBase
{
private readonly CloudAdapter Adapter;
private readonly TeamsAdapter Adapter;
private readonly IBot Bot;
public BotController(CloudAdapter adapter, IBot bot)
public BotController(TeamsAdapter adapter, IBot bot)
{
Adapter = adapter;
Bot = bot;
Expand Down
6 changes: 3 additions & 3 deletions templates/csharp/custom-copilot-rag-customize/Program.cs.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ builder.Services.AddSingleton<BotFrameworkAuthentication, ConfigurationBotFramew
// Create the Cloud Adapter with error handling enabled.
// Note: some classes expect a BotAdapter and some expect a BotFrameworkHttpAdapter, so
// register the same adapter instance for both types.
builder.Services.AddSingleton<CloudAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<CloudAdapter>());
builder.Services.AddSingleton<TeamsAdapter, AdapterWithErrorHandler>();
builder.Services.AddSingleton<IBotFrameworkHttpAdapter>(sp => sp.GetService<TeamsAdapter>());
builder.Services.AddSingleton<BotAdapter>(sp => sp.GetService<TeamsAdapter>());

builder.Services.AddSingleton<IStorage, MemoryStorage>();

Expand Down

0 comments on commit 1453452

Please sign in to comment.