Skip to content
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

refactor: update teamsAdapter #12902

Merged
merged 1 commit into from
Dec 12, 2024
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
@@ -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
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
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
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
Loading