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
@@ -0,0 +1,76 @@
<!-- setup -->

Install the Microsoft 365 Extensions package alongside the Microsoft Agents SDK:

```bash
dotnet add package Microsoft.Agents.Hosting.AspNetCore
dotnet add package Microsoft.Agents.Authentication.Msal
dotnet add package Microsoft.Teams.M365Extensions
Comment thread
singhk97 marked this conversation as resolved.
```

Add an Agents SDK host to your existing Teams SDK application, then register your Teams SDK bot with `AddTeamsSdk`:

```csharp
using Microsoft.Agents.Storage;
using Microsoft.Teams.M365Extensions;

var builder = WebApplication.CreateBuilder(args);

// Your existing Microsoft Agents SDK agent
builder.AddAgent<MyAgent>();
builder.Services.AddSingleton<IStorage, MemoryStorage>();
builder.Services.AddAgentAspNetAuthentication(builder.Configuration);

// Embed your Teams SDK bot as middleware in the Agents SDK pipeline
builder.Services.AddTeamsSdk<MyTeamsBot>();

var app = builder.Build();

app.UseAuthentication();
app.UseAuthorization();
app.MapAgentApplicationEndpoints(requireAuth: !app.Environment.IsDevelopment());

app.Run();
```

<!-- channel-routing -->

```csharp
using Microsoft.Agents.Builder;
using Microsoft.Agents.Builder.State;
using Microsoft.Teams.M365Extensions;

private async Task ChannelAsync(ITurnContext context, ITurnState state, CancellationToken ct)
{
string via = TeamsSdkMiddleware.IsTeamsChannel(context.Activity)
? "Teams turn with no matching teams.net route → fell through"
: "non-Teams channel → passed straight through";
await context.SendActivityAsync($"[Agent SDK] channelId={context.Activity.ChannelId} ({via})", cancellationToken: ct);
}
```

<!-- agents-sdk-reaction -->

```csharp
using Microsoft.Agents.Builder;
using Microsoft.Agents.Builder.State;
using Microsoft.Teams.Apps.Schema;
using Microsoft.Teams.M365Extensions;

private async Task AgentsSdkReactAsync(ITurnContext context, ITurnState state, CancellationToken ct)
{
if (!TeamsSdkMiddleware.IsTeamsChannel(context.Activity))
{
await context.SendActivityAsync("Message reactions are only available in Teams.", cancellationToken: ct);
return;
}

var response = await context.SendActivityAsync("Adding then removing a reaction.", cancellationToken: ct);
var api = _teamsBot.Api.ForServiceUrl(new Uri(context.Activity.ServiceUrl));
string conversationId = context.Activity.Conversation.Id;

await api.Conversations.AddReactionAsync(conversationId, response!.Id, ReactionTypes.Like, cancellationToken: ct);
await Task.Delay(2000, ct);
await api.Conversations.DeleteReactionAsync(conversationId, response.Id, ReactionTypes.Like, cancellationToken: ct);
}
```
10 changes: 5 additions & 5 deletions teams.md/src/pages/templates/in-depth-guides/m365-extensions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ sidebar_position: 8
title: Microsoft 365 Extensions
sidebar_label: Microsoft 365 Extensions
summary: Bridge Teams SDK and Agents SDK for multichannel.
languages: ['python', 'typescript']
languages: ['python', 'typescript', 'csharp']
---

# Microsoft 365 Extensions

Microsoft 365 Extensions let you extend an existing Teams SDK application to channels such as Direct Line and Email without rewriting any Teams-specific capabilities.

Register your existing Teams SDK handlers on the `App` returned by `useTeamsSdk` (TypeScript) or `use_teams_sdk` (Python).
Register your existing Teams SDK handlers on the `App` returned by `useTeamsSdk` (TypeScript), `use_teams_sdk` (Python), or `AddTeamsSdk` (C#).
Microsoft 365 Extensions work with your existing Teams SDK configuration and handlers.
This app is a bridge where Microsoft Agents SDK `AgentApplication` acts the multichannel host.

Expand Down Expand Up @@ -55,12 +55,12 @@ When an Agents SDK handler receives a Teams activity, it can use the Teams SDK A
<LanguageInclude section="agents-sdk-reaction" />


For a full example, the <LanguageInclude content={{"typescript": "[TypeScript Microsoft 365 Extensions sample](https://github.com/microsoft/teams.ts/tree/main/examples/m365extensions)", "python": "[Python Microsoft 365 Extensions sample](https://github.com/microsoft/teams.py/tree/main/examples/m365extensions)"}} /> demonstrates a single application running across Teams, Web Chat, and Email.
For a full example, the <LanguageInclude content={{"typescript": "[TypeScript Microsoft 365 Extensions sample](https://github.com/microsoft/teams.ts/tree/main/examples/m365extensions)", "python": "[Python Microsoft 365 Extensions sample](https://github.com/microsoft/teams.py/tree/main/examples/m365extensions)", "csharp": "[.NET Microsoft 365 Extensions sample](https://github.com/microsoft/teams.net/tree/main/samples/M365ExtensionsBot)"}} /> demonstrates a single application running across Teams, Web Chat, and Email.

## How It Works

Microsoft 365 Extensions adds a lightweight middleware bridge to your existing Teams SDK application. Aside from app initialization, your Teams-specific code stays the same.

1. **Add the bridge.** Call `useTeamsSdk` (Typescript) or `use_teams_sdk` (Python) to connect your app to Agents SDK.
1. **Add the bridge.** Call `useTeamsSdk` (TypeScript), `use_teams_sdk` (Python), or `AddTeamsSdk` (C#) to connect your app to Agents SDK.
2. **Keep your Teams logic.** Existing handlers and API client calls continue handling Teams activities.
3. **Add more channels.** Direct Line, Email, and unmatched Teams activities flow to the Agents SDK.
3. **Add more channels.** Direct Line, Email, and unmatched Teams activities flow to the Agents SDK.
3 changes: 0 additions & 3 deletions teams.md/static/missing-pages.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
"typescript",
"python"
],
"in-depth-guides/m365-extensions": [
"csharp"
],
"in-depth-guides/observability/logging": [
"csharp"
],
Expand Down
Loading