Add Api Clients with Reactions and Targeted Message support#334
Add Api Clients with Reactions and Targeted Message support#334
Conversation
Introduced a structured API facade (`TeamsBotApplication.Api`) for Teams operations, grouping functionality into Conversations, Users, Teams, Meetings, and Batch sub-APIs. Added new classes for each sub-API, with extensive XML documentation. Updated `TeamsBotApplication` to expose the new facade. Added integration tests for the API hierarchy and error handling. Cleaned up `.csproj` by removing unused RunSettings property. This refactor improves discoverability, organization, and developer experience for Teams API usage.
Added detailed tables to README.md mapping TeamsApi facade methods to their underlying REST endpoints. Documentation covers Conversations, Users (Token), Teams, Meetings, and Batch operations, including HTTP methods, endpoint paths, and relevant base URLs. Added notes on service URL usage and path parameter encoding.
There was a problem hiding this comment.
Pull request overview
This PR introduces a hierarchical Teams API facade surfaced as TeamsBotApplication.Api, organizing Teams operations into sub-APIs (Conversations/Activities/Members, Users/Token, Teams, Meetings, Batch) and adding integration tests to validate the facade structure and delegation.
Changes:
- Added
TeamsApifacade with sub-API classes for common Teams operations (activities, members, users/tokens, teams, meetings, batch). - Updated
TeamsBotApplicationto expose the facade via a newApiproperty. - Added integration tests covering API hierarchy and some error-handling behavior; removed an unused
RunSettingsFilePathproperty from the test project.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| core/test/Microsoft.Teams.Bot.Core.Tests/TeamsApiFacadeTests.cs | Adds integration tests for the new TeamsBotApplication.Api hierarchy and delegations. |
| core/test/Microsoft.Teams.Bot.Core.Tests/Microsoft.Teams.Bot.Core.Tests.csproj | Removes unused RunSettingsFilePath property group. |
| core/src/Microsoft.Teams.Bot.Apps/TeamsBotApplication.cs | Exposes new Api facade via lazy-initialized property. |
| core/src/Microsoft.Teams.Bot.Apps/Api/TeamsApi.cs | Defines top-level hierarchical facade and wires up sub-APIs. |
| core/src/Microsoft.Teams.Bot.Apps/Api/ConversationsApi.cs | Adds container for conversation-scoped APIs (Activities/Members). |
| core/src/Microsoft.Teams.Bot.Apps/Api/ActivitiesApi.cs | Adds activity operations wrapper around ConversationClient. |
| core/src/Microsoft.Teams.Bot.Apps/Api/MembersApi.cs | Adds conversation member operations wrapper around ConversationClient. |
| core/src/Microsoft.Teams.Bot.Apps/Api/UsersApi.cs | Adds container for user-scoped APIs (Token). |
| core/src/Microsoft.Teams.Bot.Apps/Api/UserTokenApi.cs | Adds user token operations wrapper around UserTokenClient. |
| core/src/Microsoft.Teams.Bot.Apps/Api/TeamsOperationsApi.cs | Adds team/channel operations wrapper around TeamsApiClient. |
| core/src/Microsoft.Teams.Bot.Apps/Api/MeetingsApi.cs | Adds meeting operations wrapper around TeamsApiClient. |
| core/src/Microsoft.Teams.Bot.Apps/Api/BatchApi.cs | Adds batch messaging and batch-operation management wrapper around TeamsApiClient. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Introduces ReactionsApi for programmatic message reactions in Teams bots, with AddAsync and DeleteAsync methods. ConversationClient now supports AddReactionAsync and DeleteReactionAsync. Expanded ReactionTypes with more documented types. Demonstrated usage in Program.cs by adding a "cake" reaction to "hello" messages.
Major update adding strong-typed handlers and payloads for all Teams invoke and event activity types (adaptive card actions, file consent, task modules, message extensions, meetings, etc.). Introduces new handler registration APIs, extensible InvokeResponse, and builder classes for adaptive card, task module, and message extension responses. Refactors schema for nullability and type-safety, unifies activity/entity types, and improves router logic. Adds new sample bots and documentation. Enhances logging, DI, and test coverage. Removes legacy code and improves maintainability throughout.
Added ArgumentNullException.ThrowIfNull for critical properties in API wrappers to ensure required parameters are not null. Refactored IConfiguration retrieval using pattern matching for clarity. Updated .slnx to exclude certain sample projects from default build. Modernized bearer token extraction and cleaned up unused usings. These changes improve code safety, error reporting, and maintainability.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 20 out of 20 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This pull request introduces support for message reactions in the Teams bot SDK, along with improvements for targeted messaging. The changes add a new `ReactionsApi` for handling reactions, expand the list of supported reaction types, and enhance message delivery to allow targeting specific recipients. The most important updates are grouped below: **Message Reaction Support** * Added a new `ReactionsApi` class, enabling bots to add and remove reactions (like, heart, laugh, etc.) on conversation activities. This includes both direct and context-based methods for reaction management. (`core/src/Microsoft.Teams.Bot.Apps/Api/ReactionsApi.cs`) * Integrated `ReactionsApi` into `ConversationsApi`, exposing it via the `Reactions` property and updating documentation to reflect its availability. (`core/src/Microsoft.Teams.Bot.Apps/Api/ConversationsApi.cs`) [[1]](diffhunk://#diff-51d32bbdd7ca8e036814a550fdcc74432bd293f447a5b105cde5714f6feddde4R16) [[2]](diffhunk://#diff-51d32bbdd7ca8e036814a550fdcc74432bd293f447a5b105cde5714f6feddde4R29) [[3]](diffhunk://#diff-51d32bbdd7ca8e036814a550fdcc74432bd293f447a5b105cde5714f6feddde4R41-R45) * Implemented `AddReactionAsync` and `DeleteReactionAsync` methods in `ConversationClient` to support adding/removing reactions through HTTP calls. (`core/src/Microsoft.Teams.Bot.Core/ConversationClient.cs`) **Expanded Reaction Types** * Extended the `ReactionTypes` class to include new reactions (checkmark, hourglass, pushpin, exclamation) and clarified existing reactions with emoji descriptions. Removed the unused `plusOne` reaction. (`core/src/Microsoft.Teams.Bot.Apps/Schema/MessageActivities/MessageReactionActivity.cs`) **Targeted Messaging Enhancements** * Added an `IsTargeted` property to `CoreActivity` and updated activity cloning to preserve this flag, enabling messages to be directed privately to specific recipients. (`core/src/Microsoft.Teams.Bot.Core/Schema/CoreActivity.cs`) [[1]](diffhunk://#diff-aa65632fe28a87aec3d29025384c7f1e687d5839d848f1220e8ed59e76dcd35bR60-R65) [[2]](diffhunk://#diff-aa65632fe28a87aec3d29025384c7f1e687d5839d848f1220e8ed59e76dcd35bR159) * Modified `SendActivityAsync`, `UpdateActivityAsync`, and `DeleteActivityAsync` methods in `ConversationClient` to handle targeted activities by appending the `isTargetedActivity=true` query parameter when appropriate. (`core/src/Microsoft.Teams.Bot.Core/ConversationClient.cs`) [[1]](diffhunk://#diff-d62a8ce4aac677906758eb430b84c9432f61ff95342701fdcae909310e2aed27R54-R58) [[2]](diffhunk://#diff-d62a8ce4aac677906758eb430b84c9432f61ff95342701fdcae909310e2aed27R91-R96) [[3]](diffhunk://#diff-d62a8ce4aac677906758eb430b84c9432f61ff95342701fdcae909310e2aed27L110-R150) [[4]](diffhunk://#diff-d62a8ce4aac677906758eb430b84c9432f61ff95342701fdcae909310e2aed27R181) * Updated `CoreActivityBuilder` to allow specifying targeted recipients via the `WithRecipient(recipient, isTargeted)` method. (`core/src/Microsoft.Teams.Bot.Core/Schema/CoreActivityBuilder.cs`) **Sample Usage** * Enhanced the Teams bot sample (`core/samples/TeamsBot/Program.cs`) to demonstrate reaction usage (adding a "cake" reaction when "hello" is received) and sending targeted messages to conversation members. These changes collectively make it easier for bot developers to manage reactions and deliver targeted messages within Teams conversations. --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Comment out or adjust assertions on Recipient in activity builder tests to reflect updated handling or population of the Recipient property. Update TeamsActivityBuilderTests to check From instead of Recipient where appropriate.
Refactored Conversation to use a primary constructor for id initialization. Updated ConversationClientTest to cache conversation ID, recipient, and agentic identity, and to consistently set the From property. Simplified test code by using the new Conversation(string id) constructor throughout. Added agentic identity support to relevant test calls. Introduced a new test for adding/removing message reactions. Improved error handling and parameter passing for paged member tests. These changes enhance test reliability, reduce duplication, and expand coverage for reaction APIs.
Add MartinCostello.Logging.XUnit to enable structured logging output in test runs. Update ConversationClientTest to accept ITestOutputHelper and configure logging to use xUnit output, with filters to reduce log noise. Pass _agenticIdentity to CreateConversationAsync. Reformat csproj for consistency.
Introduced logic in EchoBot to send a message and programmatically add/remove reactions ("laugh" and "sad") to it in Teams. Switched TeamsActivity to use a hardcoded service URL. Added WithServiceUrl(string) overload to CoreActivityBuilder for convenience. Updated tests to use new Conversation constructor and explicitly set Bot properties for improved clarity. Commented out SendUpdateDeleteActivityAsync in favor of new reaction logic.
Refactored integration test classes to use xUnit output logging via ITestOutputHelper, centralized environment variable handling in constructors, and removed redundant code. Updated all tests to use private fields for IDs and configuration, improved logging filters, and modernized test code for clarity and maintainability. No changes to test logic or assertions.
Introduce _agenticAppBlueprintId, _agenticAppId, and _agenticUserId fields to CompatTeamsInfoTests, initialized from environment variables. Use AzureAd__ClientId for botAppId and populate ChannelAccount properties with agentic identifiers to support new authentication and identity testing scenarios.
Major overhaul of TeamsBotApplication hosting model: - Remove TeamsBotApplicationBuilder; use WebApplicationBuilder/WebApplication directly. - Add AddTeamsBotApplication/UseBotApplication extension methods for registration and endpoint mapping. - Support custom bot app classes and add CustomHosting sample. Middleware pipeline improvements: - Rename ITurnMiddleWare to ITurnMiddleware; change Use() to UseMiddleware(). - Update all usages, tests, and docs for new middleware API. Service registration and API modernization: - Rename AddAuthorization to AddBotAuthorization. - Ensure AddHttpContextAccessor is always registered. - Use explicit types, collection initializers, and modern C# features. - Make ConversationClient/UserTokenClient methods virtual for testability. Update all samples and tests to new hosting and middleware model. Improve code clarity, nullability, and documentation throughout. Add copyright headers and appsettings.json for new sample.
Introduce consistent JsonSerializerOptions for ConversationClient, applying them to all serialization for requests and logs. Improve log detail and consistency. Fix DeleteActivityAsync to properly await internal call. Increase Teams logging to Trace in tests. Add nullable TeamsApi field to TeamsBotApplication.
Introduce agentic identity to Teams API and conversation client tests by reading new environment variables and constructing AgenticIdentity objects. Pass agentic identity to relevant Teams API client and facade methods. Update exception and assertion tests accordingly. Mark or skip tests that are not compatible with agentic identity, and adjust test data where needed. These changes enable testing of agentic identity scenarios in Teams bot integration tests.
Updated message handling to explicitly mark targeted messages by setting the isTargeted property in outgoing activities. The IsTargeted property is now serialized in CoreActivity, ensuring this flag is included in activity JSON payloads for downstream processing. Enhanced reply logic to use TeamsActivity with targeted recipient and mention.
isTargeted is now serialized and deserialized in activity JSON. Updated AdaptiveCardActivity.json and SuggestedActionsActivity.json to include isTargeted. Adjusted related tests to expect and verify the presence of isTargeted in JSON.
Moved IsTargeted to ConversationAccount for proper serialization. Added UpdateTargetedActivityAsync and DeleteTargetedActivityAsync. Updated routing logic and message handler for targeted messages. Expanded unit tests for targeted activity scenarios. Updated permissions for new Bash commands.
Expanded bot features with help, react, card, feedback, and task handlers. Added Adaptive Card and task module support. Improved message lifecycle handling, citation URL, and code structure.
Removed redundant overloads from MembersApi and TeamsOperationsApi, focusing on activity-based methods and stricter argument validation. Updated XML docs and return descriptions. Added TODO and summary docs to ActivitiesApi. Simplified TeamsActivityTests JSON.
Refactored TeamsApiFacadeTests to match updated method signatures, removing team ID argument when passing null activity and setting ChannelData for team context. Added new unit tests to CoreActivityBuilderTests for null handling, property assignment, and conversation reference scenarios to improve test coverage.
Added generic and activity-based overloads for retrieving conversation members and channel lists in MembersApi and TeamsOperationsApi. Updated EchoBot to set isTargeted on Recipient, send proactive TeamsActivity, and handle reactions with correct context. TeamsConversationAccount now copies IsTargeted property. CoreActivityBuilder ensures targeted flag is set before assigning recipient. These changes improve API flexibility and targeted message handling.
Changed GetByIdAsync in MembersApi to return TeamsConversationAccount instead of ConversationAccount, updating the generic type in the underlying client call to match. This ensures the method retrieves Teams-specific conversation accounts.
Changed ConversationAccount.IsTargeted to be true or null, not false, in activity builders. Updated related unit tests to expect null when not targeted. Enhanced Teams bot "react" handler to use TeamsActivity builder for richer message context before adding/removing reactions.
EchoBot's constructor now takes a TeamsBotApplication parameter in addition to ConversationState and ILogger<EchoBot>. This change ensures that an instance of TeamsBotApplication is available for use within the EchoBot class.
ReactionsApi methods now accept TeamsActivity and activityId, removing the need for manual conversationId and serviceUrl parameters. Agentic identity is derived from activity.Recipient. Program.cs updated to use new method signatures for reactions.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 36 out of 37 changed files in this pull request and generated 16 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The permissions section, which listed allowed Bash commands (dotnet, gh, and ls), has been removed from settings.local.json. This change eliminates explicit command whitelisting in the local settings file.
- URI-escape all IDs in ConversationClient URLs to prevent errors - Unify JSON serialization options for consistency - Fix null handling in WithRecipient and related tests - Correct reaction API to check activityId, not activity.Id - Update .gitignore for .claude/ and node_modules patterns - Clean up unused usings and improve formatting throughout - Clarify comments and add TODOs for recipient requirements - Minor improvements to variable declarations and method bodies
Added optional AgenticIdentity parameter to targeted activity update methods in ActivitiesApi and ConversationClient. Updated request options to use agentic identity for authentication. Enabled and added tests for sending, updating, and deleting targeted messages with agentic identity.
agenticIdentity now has a default value of null, allowing callers to omit it when updating targeted activities. This aligns its usage with customHeaders and improves API flexibility.
This pull request introduces several enhancements and new features to the Teams bot sample applications, focusing primarily on expanding the message handling capabilities, adding support for task modules, and improving targeted messaging and reactions. Additionally, it includes some cleanup and configuration changes.
Major new features and improvements:
Message handling and bot capabilities:
TeamsBot/Program.csfor commands such ashelp,targeted,react,card,feedback, andtask, each demonstrating specific Teams bot features like targeted messages, reactions, adaptive cards, and task modules. [1] [2]Task module support:
TaskModuleLauncherCardandTaskModuleFormCard, inCards.csto support task module dialogs.Targeted messaging and reactions:
CompatBotsample. [1] [2]Other improvements and cleanup:
.gitignoreto exclude the.claude/directory..claude/settings.local.jsonconfiguration file.RoutedTokenAcquisitionService.csandEchoBot.cs. [1] [2] [3]References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13]