MessageRouteAttribute(String, String, Boolean, UInt16, String) Constructor

Definition

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

public MessageRouteAttribute(string text = default, string textRegex = default, bool isAgenticOnly = false, ushort rank = 32767, string autoSignInHandlers = default);
new Microsoft.Agents.Builder.App.MessageRouteAttribute : string * string * bool * uint16 * string -> Microsoft.Agents.Builder.App.MessageRouteAttribute
Public Sub New (Optional text As String = Nothing, Optional textRegex As String = Nothing, Optional isAgenticOnly As Boolean = false, Optional rank As UShort = 32767, Optional autoSignInHandlers As String = Nothing)

Parameters

text
String

The exact message text to match (case-insensitive). Mutually exclusive with textRegex. When both are omitted, all messages are matched.

textRegex
String

A regular expression pattern matched against Text. Mutually exclusive with text.

isAgenticOnly
Boolean

When true, the route only fires for agentic turns. Defaults to false.

rank
UInt16

Route evaluation order. Lower values run first. When no text filter is specified, defaults to Last so specific-text routes take priority.

autoSignInHandlers
String

A comma/space/semicolon-delimited list of OAuth sign-in handler names, or the name of an instance or static method on the agent class matching Func<ITurnContext, string[]>.

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 RouteHandler delegate signature.

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

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

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

Applies to