Share via


AgentExtension class

Represents an extension that adds channel-specific routing functionality to an agent application. This class allows you to register routes that are only active for a specific channel.

Constructors

AgentExtension<TState>(string)

Creates a new AgentExtension instance for the specified channel.

Properties

channelId

The channel ID that this extension is associated with

Methods

addRoute(AgentApplication<TState>, Selector, RouteHandler<TurnState<DefaultConversationState, DefaultUserState, DefaultTempState>>, boolean, number)

Adds a route to the agent application that is only active for the channel specified in this extension. This method creates a channel-specific route by wrapping the provided route selector with an additional check to ensure the incoming activity matches the extension's channel ID.

Example

const teamsExtension = new AgentExtension<MyState>('msteams');
teamsExtension.addRoute(
  app,
  (context) => context.activity.type === 'message',
  async (context, state) => {
    // Handle Teams-specific message
    await context.sendActivity('Hello from Teams!');
  }
);

Constructor Details

AgentExtension<TState>(string)

Creates a new AgentExtension instance for the specified channel.

new AgentExtension(channelId: string)

Parameters

channelId

string

The channel ID that this extension will be associated with

Property Details

channelId

The channel ID that this extension is associated with

channelId: string

Property Value

string

Method Details

addRoute(AgentApplication<TState>, Selector, RouteHandler<TurnState<DefaultConversationState, DefaultUserState, DefaultTempState>>, boolean, number)

Adds a route to the agent application that is only active for the channel specified in this extension. This method creates a channel-specific route by wrapping the provided route selector with an additional check to ensure the incoming activity matches the extension's channel ID.

Example

const teamsExtension = new AgentExtension<MyState>('msteams');
teamsExtension.addRoute(
  app,
  (context) => context.activity.type === 'message',
  async (context, state) => {
    // Handle Teams-specific message
    await context.sendActivity('Hello from Teams!');
  }
);
function addRoute(app: AgentApplication<TState>, routeSelector: Selector, routeHandler: RouteHandler<TurnState<DefaultConversationState, DefaultUserState, DefaultTempState>>, isInvokeRoute?: boolean, rank?: number)

Parameters

app

AgentApplication<TState>

The agent application instance to add the route to

routeSelector
Selector

A function that determines if the route should handle the incoming activity

routeHandler

RouteHandler<TurnState<DefaultConversationState, DefaultUserState, DefaultTempState>>

The handler function that will process the activity when the route is matched

isInvokeRoute

boolean

Optional. Whether this route handles invoke activities. Defaults to false

rank

number

Optional. The priority rank of this route for routing precedence. Defaults to RouteRank.Unspecified