Language

SlackMessageRouteAttribute Class

Definition

Attribute to define a route that handles message activities, optionally matching specific text or a text 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 SlackMessageRouteAttribute : 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 SlackMessageRouteAttribute = class
    inherit Attribute
    interface IRouteAttribute
Public Class SlackMessageRouteAttribute
Inherits Attribute
Implements IRouteAttribute
Inheritance
SlackMessageRouteAttribute
Attributes
Implements

Remarks

Decorate a method with this attribute to register it as a handler for message activities. Provide text for an exact match, textRegex for a pattern match, or neither to match any message. text and textRegex are mutually exclusive. The method must match the SlackRouteHandler, RouteHandler, or TypedRouteHandler<T> of ISlackActivity delegate signature.

// Match any message
[SlackMessageRoute]
public async Task OnMessageAsync(ISlackTurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
    // Handle any message
}

// Match a specific message
[SlackMessageRoute("hello")]
public async Task OnHelloAsync(ISlackTurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
    // Handle "hello" message
}

// Match a text pattern
[SlackMessageRoute(textRegex: "he.*o")]
public async Task OnHelloPatternAsync(ISlackTurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
    // Handle messages matching pattern
}

Constructors

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

Attribute to define a route that handles message activities, optionally matching specific text or a text pattern.

Methods

Name Description
AddRoute(AgentApplication, MethodInfo)

Applies to