Skip to content

Simplify targeted messages with with_recipient() overload#275

Merged
lilyydu merged 14 commits into
mainfrom
copilot/apply-changes-from-pr-318
Feb 19, 2026
Merged

Simplify targeted messages with with_recipient() overload#275
lilyydu merged 14 commits into
mainfrom
copilot/apply-changes-from-pr-318

Conversation

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Applied changes from microsoft/teams.net#318 to simplify targeted messages API.

Changes Completed

  • Move is_targeted from _MessageBase to base ActivityInput class (as Optional[bool] = None)
  • Add is_targeted parameter to ActivityInput.with_recipient() method (optional, only sets when specified)
  • Override with_recipient() in MessageActivityInput with is_targeted parameter
  • Remove with_targeted_recipient() method from MessageActivityInput
  • Remove automatic recipient inference logic from activity_context.py
  • Add validation in ActivityContext.send() for targeted messages without recipients
  • Update error messages to reference "account" instead of "ID"
  • Update unit tests to use new with_recipient(..., is_targeted=True) API
  • Update targeted-messages example to use new API
  • Remove unused imports
  • Fix linting issues
  • Fix test error message regex

API Migration

Before: message.with_targeted_recipient(True) or message.with_targeted_recipient("user-id")
After: message.with_recipient(account, is_targeted=True)

Key Design Decisions

  1. is_targeted is Optional[bool] = None: Avoids serializing isTargeted: false for all activities, preventing potential wire-format compatibility issues with Bot Framework/Teams endpoints
  2. with_recipient() only sets is_targeted when explicitly specified: Prevents silently clearing the flag when just updating recipient. Pass is_targeted=True to enable targeting, is_targeted=False to explicitly clear it, or omit/pass None to leave unchanged
  3. Validation at send time: Clear error messages when targeted messages lack recipients, preventing 4xx errors from the service

Breaking Change

This is a breaking change requiring updates to all code using targeted messages. Recipients must now be explicitly set using Account objects.

Co-authored-by: rido-min [email protected]


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI changed the title [WIP] Apply changes from PR 318 to current repository Simplify targeted messages with with_recipient() overload Feb 11, 2026
Copilot AI requested a review from rido-min February 11, 2026 21:15
@rido-min
rido-min marked this pull request as ready for review February 11, 2026 21:25
Copilot AI review requested due to automatic review settings February 11, 2026 21:25
@rido-min

Copy link
Copy Markdown
Contributor

@copilot there are some errors, can you fix this

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 updates the Python Teams SDK’s targeted messaging API by consolidating behavior into a single with_recipient(account, is_targeted=...) method, removing with_targeted_recipient() and eliminating implicit recipient inference during ActivityContext.send().

Changes:

  • Moves is_targeted onto ActivityInput and adds an is_targeted parameter to with_recipient().
  • Removes automatic recipient inference in ActivityContext.send() and updates proactive validation messaging.
  • Migrates tests and the targeted-messages example to the new explicit-recipient pattern.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/apps/tests/test_http_plugin.py Updates targeted send test to use with_recipient(..., is_targeted=True) with an explicit Account.
packages/apps/tests/test_app.py Adjusts proactive targeted-message tests to the new API and manual is_targeted flag setting.
packages/apps/tests/test_activity_context.py Updates targeted-message context-send tests to require explicit recipient instead of inference.
packages/apps/src/microsoft_teams/apps/routing/activity_context.py Removes targeted recipient auto-inference logic in send().
packages/apps/src/microsoft_teams/apps/app.py Updates proactive targeted-message validation error text to reference with_recipient(...).
packages/api/tests/unit/test_message_activities.py Replaces with_targeted_recipient tests with with_recipient(..., is_targeted=...) coverage.
packages/api/src/microsoft_teams/api/models/activity.py Adds is_targeted to ActivityInput and extends with_recipient() signature to set targeted behavior.
packages/api/src/microsoft_teams/api/activities/message/message.py Removes _MessageBase.is_targeted and routes message with_recipient() to the base implementation.
examples/targeted-messages/src/main.py Migrates example usage to explicit-recipient targeted sends/replies/updates/deletes.

Comment thread packages/apps/tests/test_activity_context.py
Comment thread examples/targeted-messages/src/main.py
Comment thread packages/api/src/microsoft_teams/api/models/activity.py Outdated
Comment thread packages/api/src/microsoft_teams/api/models/activity.py Outdated
Comment thread packages/apps/src/microsoft_teams/apps/routing/activity_context.py
Comment thread packages/apps/src/microsoft_teams/apps/app.py Outdated

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot there are some errors, can you fix this

Fixed in 7bf13a9. The test was asserting is_targeted is None, but since we moved is_targeted to the base ActivityInput class as a non-nullable bool (default False), it now correctly checks for False instead.

@rido-min

Copy link
Copy Markdown
Contributor

@copilot apply changes based on the comments in this thread

…avior

- Change is_targeted from bool=False to Optional[bool]=None to avoid serializing false for all activities
- Update with_recipient() to only set is_targeted when explicitly specified (prevents silently clearing flag)
- Add validation in ActivityContext.send() for targeted messages without recipients
- Update error message to refer to "account" instead of "ID"
- Remove unused Account import from targeted-messages example
- Update test assertions to expect None for unset is_targeted

Co-authored-by: rido-min <[email protected]>

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot apply changes based on the comments in this thread

Applied all review comments in e193c15:

  1. Removed unused Account import from examples
  2. Changed is_targeted to Optional[bool] = None to avoid serializing false for all activities
  3. Made is_targeted parameter optional in with_recipient() - only sets when explicitly specified
  4. Added validation in ActivityContext.send() for targeted messages without recipients
  5. Updated error messages to reference "account" instead of "ID"

@rido-min

Copy link
Copy Markdown
Contributor

@copilot fix the errors

The test was expecting "explicit recipient ID" but the error message was updated to say "explicit recipient account".

Co-authored-by: rido-min <[email protected]>

Copilot AI commented Feb 11, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the errors

Fixed in 2c517fa. Updated test regex to match the new error message "explicit recipient account" instead of "explicit recipient ID".

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 9 out of 9 changed files in this pull request and generated 3 comments.

Comment thread packages/apps/tests/test_app.py
Comment thread packages/apps/tests/test_app.py Outdated
Comment thread packages/apps/src/microsoft_teams/apps/routing/activity_context.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 9 out of 9 changed files in this pull request and generated no new comments.

Comment thread packages/apps/tests/test_app.py Outdated
Comment thread packages/apps/tests/test_http_plugin.py Outdated
Comment thread packages/apps/tests/test_app.py Outdated
@lilyydu
lilyydu merged commit f392afb into main Feb 19, 2026
7 checks passed
@lilyydu
lilyydu deleted the copilot/apply-changes-from-pr-318 branch February 19, 2026 22:58
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.

4 participants