Language

SlackActivityRouteAttribute Class

Definition

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

[Microsoft.Agents.Builder.App.RouteHandlerType(typeof(Microsoft.Agents.Extensions.Slack.SlackRouteHandler))]
[Microsoft.Agents.Builder.App.RouteHandlerType(typeof(Microsoft.Agents.Builder.App.RouteHandler))]
[Microsoft.Agents.Builder.App.RouteHandlerType(typeof(Microsoft.Agents.Builder.App.TypedRouteHandler<Microsoft.Agents.Extensions.Slack.ISlackActivity>))]
[System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)]
public class SlackActivityRouteAttribute : Attribute, Microsoft.Agents.Builder.App.IRouteAttribute
[<Microsoft.Agents.Builder.App.RouteHandlerType(typeof(Microsoft.Agents.Extensions.Slack.SlackRouteHandler))>]
[<Microsoft.Agents.Builder.App.RouteHandlerType(typeof(Microsoft.Agents.Builder.App.RouteHandler))>]
[<Microsoft.Agents.Builder.App.RouteHandlerType(typeof(Microsoft.Agents.Builder.App.TypedRouteHandler<Microsoft.Agents.Extensions.Slack.ISlackActivity>))>]
[<System.AttributeUsage(System.AttributeTargets.Method, Inherited=true)>]
type SlackActivityRouteAttribute = class
    inherit Attribute
    interface IRouteAttribute
Public Class SlackActivityRouteAttribute
Inherits Attribute
Implements IRouteAttribute
Inheritance
SlackActivityRouteAttribute
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 SlackRouteHandler, RouteHandler, or TypedRouteHandler<T> of ISlackActivity delegate signature.

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

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

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

Constructors

Name Description
SlackActivityRouteAttribute(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