Simplify targeted messages with with_recipient() overload#275
Merged
Conversation
Co-authored-by: rido-min <[email protected]>
Co-authored-by: rido-min <[email protected]>
Copilot
AI
changed the title
[WIP] Apply changes from PR 318 to current repository
Simplify targeted messages with with_recipient() overload
Feb 11, 2026
rido-min
marked this pull request as ready for review
February 11, 2026 21:25
Contributor
|
@copilot there are some errors, can you fix this |
Contributor
There was a problem hiding this comment.
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_targetedontoActivityInputand adds anis_targetedparameter towith_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. |
Co-authored-by: rido-min <[email protected]>
Contributor
Author
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]>
Contributor
Author
Applied all review comments in e193c15:
|
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]>
Contributor
Author
rido-min
approved these changes
Feb 12, 2026
lilyydu
approved these changes
Feb 12, 2026
lilyydu
approved these changes
Feb 18, 2026
…to set recipient for targeted on first activity, remove value error throw
rido-min
approved these changes
Feb 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Applied changes from microsoft/teams.net#318 to simplify targeted messages API.
Changes Completed
is_targetedfrom_MessageBaseto baseActivityInputclass (asOptional[bool] = None)is_targetedparameter toActivityInput.with_recipient()method (optional, only sets when specified)with_recipient()inMessageActivityInputwithis_targetedparameterwith_targeted_recipient()method fromMessageActivityInputactivity_context.pyActivityContext.send()for targeted messages without recipientswith_recipient(..., is_targeted=True)APIAPI Migration
Before:
message.with_targeted_recipient(True)ormessage.with_targeted_recipient("user-id")After:
message.with_recipient(account, is_targeted=True)Key Design Decisions
is_targetedisOptional[bool] = None: Avoids serializingisTargeted: falsefor all activities, preventing potential wire-format compatibility issues with Bot Framework/Teams endpointswith_recipient()only setsis_targetedwhen explicitly specified: Prevents silently clearing the flag when just updating recipient. Passis_targeted=Trueto enable targeting,is_targeted=Falseto explicitly clear it, or omit/passNoneto leave unchangedBreaking 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.