Language

TeamsEventRouteAttribute Class

Definition

Attribute to define a route that handles event activities, optionally matching a specific event name or name pattern.

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

Remarks

Decorate a method with this attribute to register it as a handler for event activities. Provide name for an exact match, nameRegex for a pattern match, or neither to match any event. name and nameRegex are mutually exclusive. The method must match the TeamsRouteHandler delegate signature.

// Match any event
[TeamsEventRoute]
public async Task OnAnyEventAsync(ITeamsTurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
    // Handle any event activity
}

// Match a specific event
[TeamsEventRoute("myEvent")]
public async Task OnMyEventAsync(ITeamsTurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
    // Handle "myEvent" event
}

// Match an event name pattern
[TeamsEventRoute(nameRegex: "my.*Event")]
public async Task OnMyEventPatternAsync(ITeamsTurnContext turnContext, ITurnState turnState, CancellationToken cancellationToken)
{
    // Handle events matching pattern
}

Constructors

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

Attribute to define a route that handles event activities, optionally matching a specific event name or name pattern.

Methods

Name Description
AddRoute(AgentApplication, MethodInfo)

Applies to