Skip to content

Add TeamsExtension sample #219

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

Open
wants to merge 25 commits into
base: main
Choose a base branch
from
Open

Add TeamsExtension sample #219

wants to merge 25 commits into from

Conversation

rido-min
Copy link
Member

This pull request introduces a new Teams Agent sample, updates the solution file to include it, and makes improvements to the AspNetExtensions utility class. The most important changes include adding a new Teams Agent project with its implementation and configuration, updating the solution file to register the new project, and enhancing null safety and code readability in the AspNetExtensions class.

New Teams Agent Sample:

  • Added a new TeamsAgent project with a MyAgent implementation that handles Teams-specific features such as messaging extensions, message reactions, and conversation updates (src/samples/Teams/TeamsAgent/MyAgent.cs).
  • Created a Program.cs file to configure and run the Teams Agent application (src/samples/Teams/TeamsAgent/Program.cs).
  • Added a project file (TeamsAgent.csproj) with dependencies on Teams-related libraries (src/samples/Teams/TeamsAgent/TeamsAgent.csproj).
  • Included default appsettings.json for configuration and a Teams manifest template for deployment (src/samples/Teams/TeamsAgent/appsettings.json, src/samples/Teams/TeamsAgent/manifest/teams-manifest.TEMPLATE.jsonc) [1] [2].

Solution File Updates:

  • Updated Microsoft.Agents.SDK.sln to include the new TeamsAgent project and its configurations (src/Microsoft.Agents.SDK.sln) [1] [2] [3].

Improvements to AspNetExtensions:

  • Enhanced null safety by adding null-forgiving operators (!) to prevent potential null reference exceptions in AddAgentAspNetAuthentication (src/samples/Shared/AspNetExtensions.cs) [1] [2] [3] [4] [5].
  • Refactored the AllowedCallersPolicy class to use a primary constructor and simplified initialization of the _allowedCallers field (src/samples/Shared/AspNetExtensions.cs).
  • Improved readability by using explicit types and modern collection initializers (src/samples/Shared/AspNetExtensions.cs) [1] [2].

@github-actions github-actions bot added the ML: Samples Tags changes to samples label Apr 22, 2025
@rido-min rido-min requested a review from goldenwitch April 22, 2025 23:29
@rido-min rido-min marked this pull request as ready for review April 25, 2025 23:17
@rido-min rido-min requested a review from a team as a code owner April 25, 2025 23:17
OnActivity(ActivityTypes.Message, OnMessageAsync);
}

private async Task<MessagingExtensionResult> OnSelectItem(ITurnContext turnContext, ITurnState turnState, object item, CancellationToken cancellationToken)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this handler seems to have breaking changes from BF-SDK: https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.teams.teamsactivityhandler.onteamsmessagingextensionselectitemasync?view=botbuilder-dotnet-stable

1, The previous API requires a MessageExtensionResponse instead of MessageExtensionResult
2. The returned item was a JObject and now it's an object

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JObject is gone. That is a NewtonSoft type. This will be an issue elsewhere in Teams and we'll need to document when we develop a migration story.

Not sure about the result/response. Would need to dig and/or talk to Teams.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand JObject is gone, I was suggesting using something better than object, maybe a JsonElement, or a Dictionary. How users will know what to cast to get anything from the item?

btw, Newtonsoft is still in our dependency graph, due to Adaptive Cards :(


return await Task.FromResult(new MessagingExtensionResult
{
Type = "result",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add an Enum for this type

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are a number of places where, I believe we all agree, we need enum for things like this.
We will take this up with the teams extension team and see if we can get several of these areas improved with them.

@goldenwitch for visibility.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I love the enum suggestion.

This commit introduces a check for the `NuGetPackageName` parameter in the `OnQuery` method. If the parameter is undefined, the method now returns an empty `MessagingExtensionResult`. Additionally, the string interpolation for creating the `cardValue` has been updated to use triple quotes for improved readability and cleaner formatting of the JSON structure.
@tracyboehrer
Copy link
Member

It was my understanding we were not adding Teams samples to this repo.

@rido-min
Copy link
Member Author

It was my understanding we were not adding Teams samples to this repo.

once we move the Teams extension, we will move the samples. In the meantime we need a tample to validate the Teams extension package.

@rido-min rido-min enabled auto-merge May 6, 2025 00:27
Copy link
Member

@tracyboehrer tracyboehrer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AllowedCallers was removed because when in use (at least) Audience validation was not working. It would either need to be fixed or removed.

AspNetExtensions has also been removed from the other samples

@github-actions github-actions bot added the ML: Core Tags changes to core libraries label May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ML: Core Tags changes to core libraries ML: Samples Tags changes to samples
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants