ActivityRouteAttribute Class

Definition

Attribute to define a route that handles activities matching a specific type or type pattern.

[System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)]
public class ActivityRouteAttribute : Attribute, Microsoft.Agents.Builder.App.IRouteAttribute
[<System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)>]
type ActivityRouteAttribute = class
    inherit Attribute
    interface IRouteAttribute
Public Class ActivityRouteAttribute
Inherits Attribute
Implements IRouteAttribute
Inheritance
ActivityRouteAttribute
Attributes
Implements

Remarks

Decorate a method with this attribute to register it as a handler for activities of the specified type. Provide either type for an exact match or typeRegex for a pattern match; they are mutually exclusive. When neither is provided the route matches any activity type and defaults to Last. The method must match the RouteHandler delegate signature.

// Match by exact type
[ActivityRoute(ActivityTypes.Event)]
public async Task OnEventAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
    // Handle any event activity
}

// Match by type pattern
[ActivityRoute(typeRegex: "event|invoke")]
public async Task OnEventOrInvokeAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
    // Handle event or invoke activities
}

// Match any activity type (fires last, after all specific routes)
[ActivityRoute]
public async Task OnAnyAsync(ITurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
    // Handle any unmatched activity
}

Constructors

Name Description
ActivityRouteAttribute(String, String, Boolean, UInt16, String)

Attribute to define a route that handles activities matching a specific type or type pattern.

Methods

Name Description
AddRoute(AgentApplication, MethodInfo)

Applies to