feat(api): flatten client method chains to reduce call hops#502
Merged
Conversation
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>
Contributor
There was a problem hiding this comment.
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
ConversationClientandUserClient) 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. |
…ring sanitization' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
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>
heyitsaamir
reviewed
Jul 9, 2026
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>
heyitsaamir
approved these changes
Jul 10, 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.
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.