Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 20, 2026

All public async methods in IContext now accept an optional CancellationToken parameter, 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.Client wrapper class - all delegated async methods (Context.Client.cs)
  • IFunctionContext<T> - Send methods (FunctionContext.cs)

All parameters use CancellationToken cancellationToken = default for backward compatibility.

Example

Before:

await context.Send("Hello");
await context.SignIn(options);

After:

using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
await context.Send("Hello", cancellationToken: cts.Token);
await context.SignIn(options, cts.Token);

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
    • Triggering command: /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)
    • Triggering command: /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)
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>Add CancellationToken support to IContext.Send() methods</issue_title>
<issue_description>The IContext.Send() methods in the Teams SDK do not currently support CancellationToken parameters, which is a best practice for async methods in .NET.

Current Behavior

The Send method signatures are:

Task<MessageActivity> Send(string text, bool isTargeted = false)
Task<MessageActivity> Send(IActivity activity)
Image

Expected Behavior

All async Send methods should accept an optional CancellationToken parameter:

Task<MessageActivity> Send(string text, bool isTargeted = false, CancellationToken cancellationToken = default)
Task<MessageActivity> Send(IActivity activity, CancellationToken cancellationToken = default)

Why This Matters

  • Follows .NET async best practices
  • Enables graceful cancellation and timeout handling
  • Important for request cancellation and application shutdown scenarios</issue_description>

<agent_instructions>Review all public async methods and add the cancellation token with a default parameter. Make sure to update all the tests</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: rido-min <14916339+rido-min@users.noreply.github.com>
Copilot AI changed the title [WIP] Add CancellationToken support to IContext.Send() methods Add CancellationToken support to IContext async methods Jan 20, 2026
Copilot AI requested a review from rido-min January 20, 2026 15:14
@rido-min rido-min requested a review from singhk97 January 20, 2026 18:38
@rido-min
Copy link
Member

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.
@rido-min rido-min marked this pull request as ready for review January 20, 2026 23:18
Copilot AI review requested due to automatic review settings January 20, 2026 23:18
Copy link
Contributor

Copilot AI left a 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 CancellationToken parameters to all async methods in IContext<TActivity> (Send, Reply, Typing, SignIn, SignOut)
  • Updated the IContext.Client wrapper 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);
Copy link

Copilot AI Jan 20, 2026

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.

Suggested change
await context.Reply("this is my reply", false, CancellationToken.None);
await context.Reply("this is my reply", false);

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

@singhk97 singhk97 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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.

Add CancellationToken support to IContext.Send() methods

3 participants