-
Notifications
You must be signed in to change notification settings - Fork 15
Add CancellationToken support to IContext async methods #270
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: rido-min <14916339+rido-min@users.noreply.github.com>
|
I attest that I have verified |
Replaced context.Send with overload accepting formatting and cancellation parameters for finer control. Added context.Reply to send an additional message to the user. These changes improve message handling flexibility and response behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds CancellationToken support to all public async methods in the IContext interface, aligning with .NET async best practices. The changes maintain backward compatibility by using default parameter values.
Changes:
- Added optional
CancellationTokenparameters to all async methods inIContext<TActivity>(Send, Reply, Typing, SignIn, SignOut) - Updated the
IContext.Clientwrapper class to propagate cancellation tokens through all delegated async methods - Extended
IFunctionContext<T>Send methods with cancellation token support
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Context.Send.cs | Added cancellation token parameters to Send, Reply, and Typing methods with proper documentation |
| Context.SignIn.cs | Added cancellation token parameters to SignIn (OAuth and SSO) and SignOut methods |
| Context.Client.cs | Updated wrapper methods to accept and forward cancellation tokens to underlying context methods |
| FunctionContext.cs | Added cancellation token support to Send methods and properly forwards to app.Send |
| Program.cs | Updated sample code to demonstrate cancellation token usage (though explicitly using CancellationToken.None is unnecessary) |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| await context.Typing(); | ||
| await context.Send($"you said '{context.Activity.Text}'"); | ||
| await context.Send($"you said '{context.Activity.Text}'", false, CancellationToken.None); | ||
| await context.Reply("this is my reply", false, CancellationToken.None); |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The explicit use of CancellationToken.None is unnecessary since the cancellationToken parameter has a default value of default. This can be simplified by removing the explicit parameter to maintain cleaner code and demonstrate the backward-compatible nature of the change.
| await context.Reply("this is my reply", false, CancellationToken.None); | |
| await context.Reply("this is my reply", false); |
singhk97
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
All public async methods in
IContextnow accept an optionalCancellationTokenparameter, aligning with .NET async best practices.Changes
Modified interfaces and implementations:
IContext<TActivity>- Send, Reply, Typing, SignIn, SignOut methods (Context.Send.cs, Context.SignIn.cs)IContext.Clientwrapper class - all delegated async methods (Context.Client.cs)IFunctionContext<T>- Send methods (FunctionContext.cs)All parameters use
CancellationToken cancellationToken = defaultfor backward compatibility.Example
Before:
After:
Existing code continues to work without modification.
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:
token.botframework.com/usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/teams.net/teams.net/Tests/Microsoft.Teams.Apps.Tests/bin/Debug/net9.0/Microsoft.Teams.Apps.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/teams.net/teams.net/Tests/Microsoft.Teams.Apps.Tests/bin/Debug/net9.0/Microsoft.Teams.Apps.Tests.deps.json /home/REDACTED/work/teams.net/teams.net/Tests/Microsoft.Teams.Apps.Tests/bin/Debug/net9.0/testhost.dll --port 36801 --endpoint 127.0.0.1:036801 --role client --parentprocessid 4605 --telemetryoptedin false(dns block)/usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/teams.net/teams.net/Tests/Microsoft.Teams.Apps.Tests/bin/Debug/net9.0/Microsoft.Teams.Apps.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/teams.net/teams.net/Tests/Microsoft.Teams.Apps.Tests/bin/Debug/net9.0/Microsoft.Teams.Apps.Tests.deps.json /home/REDACTED/work/teams.net/teams.net/Tests/Microsoft.Teams.Apps.Tests/bin/Debug/net9.0/testhost.dll --port 37291 --endpoint 127.0.0.1:037291 --role client --parentprocessid 6014 --telemetryoptedin false(dns block)/usr/share/dotnet/dotnet /usr/share/dotnet/dotnet exec --runtimeconfig /home/REDACTED/work/teams.net/teams.net/Tests/Microsoft.Teams.Apps.Tests/bin/Debug/net9.0/Microsoft.Teams.Apps.Tests.runtimeconfig.json --depsfile /home/REDACTED/work/teams.net/teams.net/Tests/Microsoft.Teams.Apps.Tests/bin/Debug/net9.0/Microsoft.Teams.Apps.Tests.deps.json /home/REDACTED/work/teams.net/teams.net/Tests/Microsoft.Teams.Apps.Tests/bin/Debug/net9.0/testhost.dll --port 41847 --endpoint 127.0.0.1:041847 --role client --parentprocessid 6657 --telemetryoptedin false(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.