Language

TeamsQueryRouteAttribute Class

Definition

Attribute to define a route that handles Teams message extension query events for a specific command.

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

Remarks

Decorate a method with this attribute to register it as a handler for message extension query events in Teams. The method must match the QueryHandler delegate signature.

[TeamsQueryRoute("searchProducts")]
public async Task<Response> OnSearchProductsAsync(ITeamsTurnContext turnContext, ITurnState turnState, Microsoft.Teams.Api.MessageExtensions.Query query, CancellationToken cancellationToken)
{
    var keyword = query.Parameters.FirstOrDefault()?.Value ?? string.Empty;
    var items = await _catalog.SearchAsync(keyword, cancellationToken);
    var attachments = items.Select(i => i.ToHeroCard().ToMessagingExtensionAttachment()).ToList();
    return new Response { ComposeExtension = new Result { Type = ResultType.List, Attachments = attachments } };
}

Alternatively, OnQuery(String, QueryHandler, String[], UInt16) can be used to register the handler via the fluent API.

Constructors

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

Attribute to define a route that handles Teams message extension query events for a specific command.

Methods

Name Description
AddRoute(AgentApplication, MethodInfo)

Applies to