Skip to content

fix: drop recipient from targeted message update payload - #571

Open
Corina (corinagum) wants to merge 1 commit into
mainfrom
cg/targeted-update-recipient
Open

fix: drop recipient from targeted message update payload#571
Corina (corinagum) wants to merge 1 commit into
mainfrom
cg/targeted-update-recipient

Conversation

@corinagum

Copy link
Copy Markdown
Contributor

Ports microsoft/teams.ts#739 (fixes microsoft/teams.ts#738) to the Python SDK. Same bug, same root cause, no equivalent issue filed on this repo.

Why

Updating a targeted message through ctx.send fails. Setting id on a MessageActivityInput that also carries a targeted recipient correctly routes the call to update_targeted_activity, but recipient is still serialized into the request body, and Teams rejects it:

400 Bad Request
BadArgument: Cannot edit Recipient of Targeted Message

The recipient of an existing targeted message cannot be edited, so it must not appear in an update payload. It is only useful for deciding which endpoint to call.

What changed

send_or_update_activity in packages/apps/src/microsoft_teams/apps/activity_send.py (the Python counterpart of TypeScript's ActivitySender) now splits the targeted update out of the shared update path:

  • The recipient still selects the targeted endpoint, then is dropped from the outbound payload via activity.model_copy(update={"recipient": None}). The client dumps with exclude_none=True, so the key disappears from the wire body.
  • The returned SentActivity still reports the recipient the caller passed in. Without this, result.activity_params.recipient would come back None after an update, which matches the guarantee the TypeScript fix makes about its own return value.

This covers every send path, since ctx.send, App.send, and FunctionContext.send all funnel through this helper.

Deliberately unchanged: ConversationActivityClient.update_targeted still sends whatever it is handed. examples/targeted-messages calls that client directly and passes no recipient, so it is unaffected, and this keeps the fix at the same layer as the TypeScript port rather than diverging the two SDKs at the API-client boundary.

Tests

test_targeted_update_preserves_recipient asserted the buggy behavior, so it is replaced by test_targeted_update_drops_recipient_from_payload, which checks that the targeted endpoint is still chosen, the payload has no recipient (both on the model and in the serialized body), and the caller still gets the recipient back.

Red-green verified rather than assumed: reverting either half of the fix independently fails the new test.

Validation

  • pytest packages1052 passed
  • pyright — 0 errors, 0 warnings
  • ruff check / ruff format --check — clean

Teams rejects targeted-message updates that carry a recipient with
"BadArgument: Cannot edit Recipient of Targeted Message", because the recipient of an existing targeted message cannot be edited.

send_or_update_activity now uses the recipient only to select the targeted update endpoint and strips it from the outbound payload. The returned SentActivity still reports the recipient the caller passed in.

Ports microsoft/teams.ts#739 (fixes microsoft/teams.ts#738).

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3793b160-edf5-405b-a920-5c774273b68b
Copilot AI lite review requested due to automatic review settings August 24, 2026 21:52

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

Fixes targeted message updates by ensuring recipient is used only to select the targeted update endpoint and is not serialized into the update request body (which Teams rejects). This aligns the Python SDK behavior with the referenced TypeScript fix and preserves the caller-visible recipient in the returned SentActivity.

Changes:

  • In targeted update flows, create an update payload with recipient=None so it is omitted from the wire body (exclude_none=True), while preserving the original recipient in the returned result.
  • Update/replace the targeted update test to assert endpoint selection, payload serialization behavior, and that the caller still receives the original recipient.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
packages/apps/src/microsoft_teams/apps/activity_send.py Drops recipient from targeted update payloads while keeping it on the returned SentActivity.
packages/apps/tests/test_activity_context.py Replaces the prior assertion with a test that verifies recipient is omitted from the targeted update payload but preserved for the caller.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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.

[Bug]: Targeted message update via ctx.send sends recipient and fails

2 participants