Skip to content

Add support for Targeted Messages#303

Merged
ShanmathiMayuramKrithivasan merged 5 commits intomicrosoft:mainfrom
ShanmathiMayuramKrithivasan:shmayura/targeted-messages-v2
Feb 4, 2026
Merged

Add support for Targeted Messages#303
ShanmathiMayuramKrithivasan merged 5 commits intomicrosoft:mainfrom
ShanmathiMayuramKrithivasan:shmayura/targeted-messages-v2

Conversation

@ShanmathiMayuramKrithivasan
Copy link
Copy Markdown
Collaborator

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

Copilot AI review requested due to automatic review settings February 2, 2026 13:14
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 IsTargeted property and WithTargetedRecipient helper methods to MessageActivity
  • Implemented CreateTargetedAsync, UpdateTargetedAsync, and DeleteTargetedAsync methods in ActivityClient
  • Added routing logic to automatically use targeted endpoints when IsTargeted is 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.

Comment thread Libraries/Microsoft.Teams.Apps/App.cs
Comment thread Libraries/Microsoft.Teams.Apps/Contexts/Context.Send.cs
Comment thread Tests/Microsoft.Teams.Api.Tests/Clients/ActivityClientTests.cs
Comment thread Tests/Microsoft.Teams.Api.Tests/Clients/ActivityClientTests.cs
Comment thread Tests/Microsoft.Teams.Api.Tests/Clients/ActivityClientTests.cs
Comment thread Libraries/Microsoft.Teams.Apps/App.cs Outdated
Comment thread Libraries/Microsoft.Teams.Apps/Contexts/Context.Send.cs Outdated
Comment thread Libraries/Microsoft.Teams.Api/Activities/Message/MessageActivity.cs Outdated
Comment thread Libraries/Microsoft.Teams.Api/Clients/ActivityClient.cs
Comment thread Libraries/Microsoft.Teams.Api/Activities/Message/MessageActivity.cs
Comment thread Samples/Samples.TargetedMessages/Properties/launchSettings.json Outdated
Copilot AI review requested due to automatic review settings February 3, 2026 01:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread Libraries/Microsoft.Teams.Api/Activities/Message/MessageActivity.cs
Comment thread Libraries/Microsoft.Teams.Api/Clients/ActivityClient.cs
Comment thread Tests/Microsoft.Teams.Api.Tests/Activities/Message/MessageActivityTests.cs Outdated
Copilot AI review requested due to automatic review settings February 3, 2026 02:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread Tests/Microsoft.Teams.Apps.Tests/AppTests.cs
Copy link
Copy Markdown
Member

@rido-min rido-min left a comment

Choose a reason for hiding this comment

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

approving for preview, there are still some details related to the Recipient before we get into stable a stable release.

@ShanmathiMayuramKrithivasan ShanmathiMayuramKrithivasan merged commit 6867e90 into microsoft:main Feb 4, 2026
14 checks passed
ShanmathiMayuramKrithivasan added a commit to ShanmathiMayuramKrithivasan/teams.net that referenced this pull request Mar 10, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants