BotApplication.ProcessAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
| Name | Description |
|---|---|
| ProcessAsync(HttpContext, CancellationToken) |
Processes an incoming HTTP request containing a bot activity. |
| ProcessAsync(CoreActivity, ClaimsPrincipal, String, CancellationToken) |
Processes an already-received bot activity, independent of the transport it arrived on. |
ProcessAsync(HttpContext, CancellationToken)
Processes an incoming HTTP request containing a bot activity.
public virtual System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Http.HttpContext httpContext, System.Threading.CancellationToken cancellationToken = default);
abstract member ProcessAsync : Microsoft.AspNetCore.Http.HttpContext * System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.ProcessAsync : Microsoft.AspNetCore.Http.HttpContext * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overridable Function ProcessAsync (httpContext As HttpContext, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- httpContext
- HttpContext
The HTTP context containing the incoming bot activity request.
- cancellationToken
- CancellationToken
A cancellation token that can be used to cancel the initial deserialization. Note: a dedicated timeout governs activity processing.
Returns
A task that represents the asynchronous activity processing operation.
Exceptions
Thrown if the request body cannot be deserialized into a valid activity.
Thrown if the activity's service URL does not match the serviceurl claim of the authenticated caller.
Thrown if an error occurs while processing the activity, wrapping the original exception and the offending CoreActivity. Also thrown when processing exceeds ProcessActivityTimeout and the pipeline observes the resulting cancellation, in which case InnerException is a TimeoutException. A TimeoutException thrown by a handler is wrapped the same way, so an inner TimeoutException does not by itself indicate that ProcessActivityTimeout elapsed. The timeout is cooperative: a handler that ignores its cancellation token or performs blocking I/O keeps running past the timeout and is not surfaced this way. The timeout is disabled when a debugger is attached.
Remarks
The request body is deserialized into a CoreActivity and handed to ProcessAsync(CoreActivity, ClaimsPrincipal, String, CancellationToken) together with the request's authenticated User and MS-CV correlation vector.
A dedicated internal timeout (configurable via ProcessActivityTimeout, default 5 minutes) is used instead of the HTTP request's cancellation token, because streaming handlers may outlive the original HTTP connection. When a debugger is attached the timeout is disabled.
Entra tokens not requested by the Agent 365 platform are rejected with 401 Unauthorized.
Applies to
ProcessAsync(CoreActivity, ClaimsPrincipal, String, CancellationToken)
Processes an already-received bot activity, independent of the transport it arrived on.
public virtual System.Threading.Tasks.Task ProcessAsync(Microsoft.Teams.Core.Schema.CoreActivity activity, System.Security.Claims.ClaimsPrincipal? user, string? correlationVector, System.Threading.CancellationToken cancellationToken = default);
abstract member ProcessAsync : Microsoft.Teams.Core.Schema.CoreActivity * System.Security.Claims.ClaimsPrincipal * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task
override this.ProcessAsync : Microsoft.Teams.Core.Schema.CoreActivity * System.Security.Claims.ClaimsPrincipal * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task
Public Overridable Function ProcessAsync (activity As CoreActivity, user As ClaimsPrincipal, correlationVector As String, Optional cancellationToken As CancellationToken = Nothing) As Task
Parameters
- activity
- CoreActivity
The activity to process. Cannot be null.
- user
- ClaimsPrincipal
The authenticated caller. When it carries a serviceurl claim, the claim must match
ServiceUrl exactly. Pass null when the transport has no per-activity principal.
- correlationVector
- String
Optional correlation vector used for logging (the HTTP transport supplies the MS-CV header).
- cancellationToken
- CancellationToken
Reserved for the caller's cancellation. Note: a dedicated timeout governs activity processing.
Returns
A task that represents the asynchronous activity processing operation.
Exceptions
Thrown if the activity's service URL does not match the serviceurl claim of user.
Thrown if an error occurs while processing the activity, wrapping the original exception and the offending CoreActivity. Also thrown when processing exceeds ProcessActivityTimeout and the pipeline observes the resulting cancellation, in which case InnerException is a TimeoutException. A TimeoutException thrown by a handler is wrapped the same way, so an inner TimeoutException does not by itself indicate that ProcessActivityTimeout elapsed. The timeout is cooperative: a handler that ignores its cancellation token or performs blocking I/O keeps running past the timeout and is not surfaced this way. The timeout is disabled when a debugger is attached.
Remarks
The activity is run through the registered middleware pipeline (see UseMiddleware(ITurnMiddleware)) and finally dispatched to OnActivity. The HTTP overload ProcessAsync(HttpContext, CancellationToken) delegates here; other transports call this overload directly. Any response to the sender (such as an invoke response) is the handler's concern, not this method's.
A dedicated internal timeout (configurable via ProcessActivityTimeout, default 5 minutes) governs processing, because streaming handlers may outlive the inbound connection. When a debugger is attached the timeout is disabled.