The state type extending TurnState.
Creates a new instance of AgentApplication.
The state type extending TurnState.
Optionaloptions: Partial<AgentApplicationOptions<TState>>Optional configuration options for the application.
The constructor initializes the application with default settings and applies any provided options. It sets up the adapter, authorization, and other core components based on the configuration.
Default options:
Protected Readonly_Protected Readonly_Protected Readonly_Protected Readonly_Protected Readonly_Gets the adaptive cards actions handler for the application.
The adaptive cards actions instance.
Gets the authorization instance for the application.
The authorization instance.
Gets the options used to configure the application.
The application options.
Adds a new route to the application for handling activities.
The selector function that determines if a route should handle the current activity.
The handler function that will be called if the selector returns true.
Whether this route is for invoke activities. Defaults to false.
The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
Array of authentication handler names for this route. Defaults to empty array.
Whether this route is for agentic requests only. Defaults to false.
The current instance of the application.
ProtectedcallCalls a series of event handlers in sequence.
The turn context for the current conversation.
The current turn state.
Array of event handlers to call.
A promise that resolves to true if all handlers returned true, false otherwise.
ProtectedcontinueContinues a conversation asynchronously.
The conversation reference or turn context.
The logic to execute during the conversation.
A promise that resolves when the conversation logic has completed.
Adds a handler for specific activity types.
The activity type(s) to handle. Can be a string, RegExp, RouteSelector, or array of these types.
The handler function that will be called when the specified activity type is received.
Array of authentication handler names for this activity. Defaults to empty array.
The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
Indicates if this handler is for agentic requests only. Defaults to false.
The current instance of the application.
Adds a handler for conversation update events.
The conversation update event to handle (e.g., 'membersAdded', 'membersRemoved').
The handler function that will be called when the specified event occurs.
Array of authentication handler names for this event. Defaults to empty array.
The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
Indicates if this handler is for agentic requests only. Defaults to false.
The current instance of the application.
Sets an error handler for the application.
The error handler function to be called when an error occurs.
The current instance of the application.
Adds a handler for message activities that match the specified keyword or pattern.
The keyword, pattern, or selector function to match against message text. Can be a string, RegExp, RouteSelector, or array of these types.
The handler function that will be called when a matching message is received.
Array of authentication handler names for this message handler. Defaults to empty array.
The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
Indicates if this handler is for agentic requests only. Defaults to false.
The current instance of the application.
This method allows you to register handlers for specific message patterns. If keyword is a string, it matches messages containing that string. If keyword is a RegExp, it tests the message text against the regular expression. If keyword is a function, it calls the function with the context to determine if the message matches.
Adds a handler for message reaction added events.
The handler function that will be called when a message reaction is added.
The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
Indicates if this handler is for agentic requests only. Defaults to false.
The current instance of the application.
Adds a handler for message reaction removed events.
The handler function that will be called when a message reaction is removed.
The rank of the route, used to determine the order of evaluation. Defaults to RouteRank.Unspecified.
Indicates if this handler is for agentic requests only. Defaults to false.
The current instance of the application.
Sets a handler to be called when a sign-in attempt fails.
The handler function to be called after a failed sign-in attempt.
The current instance of the application.
Sets a handler to be called when a user successfully signs in.
The handler function to be called after successful sign-in.
The current instance of the application.
Adds an event handler for specified turn events.
The turn event(s) to handle. Can be 'beforeTurn', 'afterTurn', or other custom events.
The handler function that will be called when the event occurs.
The current instance of the application.
Registers an extension with the application.
The extension type extending AgentExtension.
Executes the application logic for a given turn context.
The context for the current turn of the conversation.
A promise that resolves when the application logic has completed.
Executes the application logic for a given turn context.
The context for the current turn of the conversation.
A promise that resolves to true if a handler was executed, false otherwise.
This is the core internal method that processes a turn in the conversation.
It handles routing and executing handlers based on the activity type and content.
While this method is public, it's typically called internally by the run method.
The method performs the following operations:
Sends a proactive message to a conversation.
The turn context or conversation reference to use.
The activity or text to send.
Optionalspeak: stringOptional text to be spoken by the bot on a speech-enabled channel.
OptionalinputHint: stringOptional input hint for the activity.
A promise that resolves to the resource response from sending the activity.
ProtectedstartStarts a long-running call, potentially in a new conversation context.
The turn context for the current conversation.
The handler function to execute.
A promise that resolves to the result of the handler.
Starts a typing indicator timer for the current turn context.
The turn context for the current conversation.
void
This method starts a timer that sends typing activity indicators to the user at regular intervals. The typing indicator continues until a message is sent or the timer is explicitly stopped.
The typing indicator helps provide feedback to users that the agent is processing their message, especially when responses might take time to generate.
Stops the typing indicator timer if it's currently running.
void
Main application class for handling agent conversations and routing.
Remarks
The AgentApplication class provides a framework for building conversational agents. It handles routing activities to appropriate handlers, manages conversation state, supports authentication flows, and provides various event handling capabilities.
Key features:
Example