Skip to content

feat(api): flatten client method chains to reduce call hops#502

Merged
lilyydu merged 4 commits into
mainfrom
lilyydu/flatten-clients
Jul 10, 2026
Merged

feat(api): flatten client method chains to reduce call hops#502
lilyydu merged 4 commits into
mainfrom
lilyydu/flatten-clients

Conversation

@lilyydu

@lilyydu lilyydu commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

Port of microsoft/teams.ts#634. Promotes grouped sub-client methods onto their parent clients so common calls drop from 3 hops to 2. Additive and backward compatible: the existing chained accessors remain as deprecated aliases.

Port of microsoft/teams.ts#634. Promotes grouped sub-client methods onto
their parent clients so common calls drop from 3 hops to 2. Additive and
backward compatible: the existing chained accessors remain as deprecated
aliases.

- UserClient: add get_token, get_aad_tokens, get_token_status, sign_out,
  exchange_token; deprecate the `token` accessor.
- ConversationClient: add flattened activity/member methods and
  add_reaction/delete_reaction (new internal ReactionClient); deprecate
  the activities() and members() grouped accessors.
- ApiClient: deprecate the bots and reactions accessors (backed by private
  _bots/_reactions); mark the BotClient class deprecated.
- Migrate internal callers (http_stream, activity_sender, app_process,
  app_oauth, activity_context, function_context) to the flattened API.
- Update examples (reactions, proactive-messaging, message-extensions,
  targeted-messages) to the flattened API.
- Add flattened-method and deprecation-warning tests; update caller mocks.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings July 9, 2026 22:09
Comment thread packages/api/tests/unit/test_user_client.py Fixed
Comment thread packages/api/tests/unit/test_user_client.py Fixed

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 ports the “flattened client method” pattern from teams.ts to teams.py, promoting commonly used sub-client operations onto their parent clients (e.g. conversations.create_activity(...) instead of conversations.activities(...).create(...)) to reduce call-chain hops while keeping the previous chained APIs as deprecated aliases.

Changes:

  • Added flattened methods on API clients (notably ConversationClient and UserClient) and updated apps-layer call sites accordingly.
  • Updated unit tests and examples to use the new flattened methods (including new tests that assert deprecated accessors still warn and function).
  • Routed reactions operations through ConversationClient (e.g. conversations.add_reaction(...)) and added associated tests.

Reviewed changes

Copilot reviewed 24 out of 24 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/apps/tests/test_http_stream.py Updates mocks to match flattened conversations.create_activity/update_activity call signatures.
packages/apps/tests/test_function_context.py Updates membership lookup mock to conversations.get_member_by_id.
packages/apps/tests/test_app_process.py Updates token retrieval mocking to users.get_token.
packages/apps/tests/test_app_oauth.py Updates OAuth handler tests to use users.exchange_token/get_token.
packages/apps/tests/test_activity_sender.py Updates sender tests to assert flattened conversation activity calls and new parameter order.
packages/apps/tests/test_activity_context.py Updates sign-in/sign-out tests to use flattened token methods and updated bot sign-in access.
packages/apps/src/microsoft_teams/apps/routing/activity_context.py Uses flattened users.get_token/sign_out; updates bot sign-in resource call site.
packages/apps/src/microsoft_teams/apps/http_stream.py Switches streaming updates/creates to flattened conversation activity methods.
packages/apps/src/microsoft_teams/apps/contexts/function_context.py Uses flattened conversations.get_member_by_id to validate membership.
packages/apps/src/microsoft_teams/apps/app_process.py Uses flattened users.get_token during context build.
packages/apps/src/microsoft_teams/apps/app_oauth.py Uses flattened users.exchange_token/get_token in OAuth flows.
packages/apps/src/microsoft_teams/apps/activity_sender.py Switches sender to flattened conversation activity methods and avoids deprecated grouped accessor.
packages/api/tests/unit/test_user_client.py Adds unit tests for flattened UserClient methods and deprecation behavior of .token.
packages/api/tests/unit/test_conversation_client.py Adds unit tests for flattened ConversationClient methods plus deprecation tests for grouped accessors.
packages/api/tests/unit/test_api_client.py Updates for _bots + adds tests for deprecated bots/reactions accessors and routing behavior.
packages/api/src/microsoft_teams/api/clients/user/client.py Implements flattened token operations on UserClient and deprecates grouped .token accessor.
packages/api/src/microsoft_teams/api/clients/conversation/client.py Implements flattened activity/member/reaction operations on ConversationClient; deprecates grouped accessors.
packages/api/src/microsoft_teams/api/clients/bot/client.py Marks BotClient as deprecated.
packages/api/src/microsoft_teams/api/clients/bot/init.py Suppresses type-checker deprecation noise when exporting BotClient.
packages/api/src/microsoft_teams/api/clients/api_client.py Renames bots field to _bots, adds deprecated bots accessor, and deprecates reactions accessor in favor of conversations.*.
examples/targeted-messages/src/main.py Updates example to flattened targeted activity update/delete methods.
examples/reactions/src/main.py Routes reaction add/delete through conversations.add_reaction/delete_reaction.
examples/proactive-messaging/src/main.py Updates proactive update example to conversations.update_activity.
examples/message-extensions/src/main.py Updates members fetch example to conversations.get_members.

Comment thread packages/api/src/microsoft_teams/api/clients/api_client.py
Comment thread packages/api/src/microsoft_teams/api/clients/api_client.py
Comment thread packages/apps/src/microsoft_teams/apps/routing/activity_context.py
…ring sanitization'

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Comment thread packages/api/tests/unit/test_user_client.py Fixed
Comment thread packages/api/tests/unit/test_user_client.py Fixed
Replace `"<url>" in response` / `in response.keys()` membership checks with
`response.get("<url>") is not None`. CodeQL's incomplete-url-substring-
sanitization rule flags the URL-literal membership pattern (bypassable when
used to sanitize untrusted URLs); here `response` is a dict, so exact-key
`.get()` is equivalent, clearer, and not flagged. Also updates the two
pre-existing get_aad tests for consistency.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Comment thread packages/api/src/microsoft_teams/api/clients/conversation/client.py
Port of the TODO markers from microsoft/teams.ts#634. Annotate the
underlying ConversationActivityClient, ConversationMemberClient and
ReactionClient methods with "TODO: Will be deprecated alongside accessor
in ConversationClient", matching the TS change now that the flattened
ConversationClient methods are the preferred entry points.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@lilyydu lilyydu merged commit 87498ab into main Jul 10, 2026
8 checks passed
@lilyydu lilyydu deleted the lilyydu/flatten-clients branch July 10, 2026 16:08
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