-
Notifications
You must be signed in to change notification settings - Fork 272
docs: add M365 Extensions guide for .NET #2966
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
Merged
+81
−8
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
b577c54
docs: add M365 Extensions guide for .NET
singhk97 b0e5dd3
docs: add How It Works diagram to M365 Extensions guide
singhk97 9f1ddb4
Merge branch 'main' of https://github.com/microsoft/teams-sdk into si…
Copilot a20430d
docs: address review feedback on M365 Extensions C# guide
singhk97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
teams.md/src/components/include/in-depth-guides/m365-extensions/csharp.incl.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| ``` | ||
|
|
||
| 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); | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.