Add support for Targeted Messages#303
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds support for targeted messages in Microsoft Teams bots, allowing messages to be visible only to specific recipients within group conversations. The implementation includes SDK changes, API client methods, validation logic, comprehensive tests, and a sample application.
Changes:
- Added
IsTargetedproperty andWithTargetedRecipienthelper methods toMessageActivity - Implemented
CreateTargetedAsync,UpdateTargetedAsync, andDeleteTargetedAsyncmethods inActivityClient - Added routing logic to automatically use targeted endpoints when
IsTargetedis true - Added validation to ensure proactive targeted messages have explicit recipients
- Included unit tests for the new functionality and a complete sample application
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 9 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Microsoft.Teams.Api.Tests/Clients/ActivityClientTests.cs | Unit tests for ActivityClient targeted message methods (create, update, delete) |
| Tests/Microsoft.Teams.Api.Tests/Activities/Message/MessageActivityTests.cs | Unit tests for WithTargetedRecipient helper methods and JSON serialization |
| Samples/Samples.TargetedMessages/appsettings.json | Configuration file for sample application |
| Samples/Samples.TargetedMessages/appsettings.Development.json | Development-specific configuration for sample |
| Samples/Samples.TargetedMessages/Samples.TargetedMessages.csproj | Project file for targeted messages sample |
| Samples/Samples.TargetedMessages/README.md | Comprehensive documentation with examples and API details |
| Samples/Samples.TargetedMessages/Properties/launchSettings.json | Launch configuration for sample application |
| Samples/Samples.TargetedMessages/Program.cs | Sample bot demonstrating all targeted message operations |
| Microsoft.Teams.sln | Added sample project to solution |
| Libraries/Microsoft.Teams.Plugins/Microsoft.Teams.Plugins.AspNetCore/AspNetCorePlugin.cs | Routing logic to use targeted endpoints based on IsTargeted flag |
| Libraries/Microsoft.Teams.Apps/Contexts/Context.Send.cs | Auto-sets recipient to Activity.From for reactive targeted messages |
| Libraries/Microsoft.Teams.Apps/App.cs | Validates that proactive targeted messages have explicit recipients |
| Libraries/Microsoft.Teams.Api/Clients/ActivityClient.cs | API methods for targeted create, update, and delete operations |
| Libraries/Microsoft.Teams.Api/Activities/Message/MessageActivity.cs | Added IsTargeted property and WithTargetedRecipient methods |
Comments suppressed due to low confidence (1)
Libraries/Microsoft.Teams.Api/Activities/Message/MessageActivity.cs:266
- The IsTargeted property is not merged in the Merge method, but other nullable properties like Importance, DeliveryMode, and Expiration are merged using the null-coalescing operator. For consistency with other nullable properties in MessageActivity, consider adding IsTargeted ??= from.IsTargeted; to the Merge method.
public MessageActivity Merge(MessageActivity from)
{
base.Merge(from);
Text ??= from.Text;
Speak ??= from.Speak;
InputHint ??= from.InputHint;
Summary ??= from.Summary;
TextFormat ??= from.TextFormat;
AttachmentLayout ??= from.AttachmentLayout;
SuggestedActions ??= from.SuggestedActions;
Importance ??= from.Importance;
DeliveryMode ??= from.DeliveryMode;
Expiration ??= from.Expiration;
Value ??= from.Value;
AddAttachment(from.Attachments?.ToArray() ?? []);
return this;
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
rido-min
left a comment
There was a problem hiding this comment.
approving for preview, there are still some details related to the Recipient before we get into stable a stable release.
Adds support for targeted messages that only a specific recipient can
see in a conversation.
**Usage**
```
// Target the sender from context
await context.Send(
new MessageActivity("Only you see this!")
.WithTargetedRecipient(true)
);
// Target a specific user
await context.Send(
new MessageActivity("Private message")
.WithTargetedRecipient("user-id")
);
```
**Key Changes**
- SDK appends ?isTargetedActivity=true to API calls, so backend services
handles the messages accordingly
- Supports create, update, delete, and reply operations
- Includes tests and sample bot
Adds support for targeted messages that only a specific recipient can see in a conversation.
Usage
Key Changes