Add per-call CancellationToken to async client methods#395
Conversation
Co-authored-by: rido-min <14916339+rido-min@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/teams.net/sessions/af2ce572-3628-4603-ab76-71409c500b79
|
@copilot can you fix the build errors? https://github.com/microsoft/teams.net/actions/runs/23601007928/job/68730822637?pr=395 |
…ken matcher to Moq expressions Co-authored-by: rido-min <14916339+rido-min@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/teams.net/sessions/cf26ee0c-36ea-433a-acb5-c35ad63353a2
Fixed in f32780a. The Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
|
@copilot review all the samples to make sure we use the new cancellationToken overload |
Agent-Logs-Url: https://github.com/microsoft/teams.net/sessions/49a85133-ce35-492b-879a-6c85895d36f2 Co-authored-by: rido-min <14916339+rido-min@users.noreply.github.com>
Done in a3d2f8a. Two samples were calling
The other samples ( |
|
I attest that I have verified |
There was a problem hiding this comment.
Pull request overview
Adds per-call cancellation support across Microsoft.Teams.Api.Clients async methods (and updates samples/tests accordingly) to avoid relying solely on the instance-level _cancellationToken.
Changes:
- Added
CancellationToken cancellationToken = defaultto multiple client async methods and used a fallback to_cancellationTokenwhen not provided. - Updated samples to pass the handler
cancellationTokeninto client calls. - Updated tests/mocks to match the new method signatures.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Microsoft.Teams.Apps.Tests/AppTests.cs | Updates Moq setups/verifications to include the new CancellationToken parameter. |
| Samples/Samples.TargetedMessages/Program.cs | Passes handler cancellationToken into Conversations/Members and targeted activity APIs. |
| Samples/Samples.Reactions/Program.cs | Passes handler cancellationToken into reaction client calls. |
| Libraries/Microsoft.Teams.Api/Clients/ActivityClient.cs | Adds per-call CancellationToken to activity CRUD + targeted activity methods. |
| Libraries/Microsoft.Teams.Api/Clients/BotSignInClient.cs | Adds per-call CancellationToken to bot sign-in APIs. |
| Libraries/Microsoft.Teams.Api/Clients/BotTokenClient.cs | Adds per-call CancellationToken to bot token acquisition APIs. |
| Libraries/Microsoft.Teams.Api/Clients/ConversationClient.cs | Adds per-call CancellationToken to conversation creation API. |
| Libraries/Microsoft.Teams.Api/Clients/MeetingClient.cs | Adds per-call CancellationToken to meeting APIs. |
| Libraries/Microsoft.Teams.Api/Clients/MemberClient.cs | Adds per-call CancellationToken to member APIs. |
| Libraries/Microsoft.Teams.Api/Clients/TeamClient.cs | Adds per-call CancellationToken to team APIs. |
| Libraries/Microsoft.Teams.Api/Clients/UserTokenClient.cs | Adds per-call CancellationToken to user token APIs. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
I attest that I have verified
All async methods in
Microsoft.Teams.Api.Clientsused a single_cancellationTokenbaked in at construction time, making per-call cancellation impossible and shared-instance cancellation a blunt instrument.ReactionClientalready had the correct pattern; this brings all other clients into alignment.Changes
CancellationToken cancellationToken = defaultto every async method in:ActivityClient,BotSignInClient,BotTokenClient,ConversationClient,MeetingClient,MemberClient,TeamClient,UserTokenClientReactionClient:Samples.TargetedMessagesandSamples.Reactionsto pass the handler'scancellationTokento allcontext.Api.*client method calls, using the new per-call overloads.Fully backwards-compatible — existing callers are unaffected since the parameter defaults to
default.💡 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.