Share via


Application<TState> Class

Definition

Application class for routing and processing incoming requests.

public class Application<TState> : Microsoft.Bot.Builder.IBot where TState : TurnState, new()
type Application<'State (requires 'State :> TurnState and 'State : (new : unit -> 'State))> = class
    interface IBot
Public Class Application(Of TState)
Implements IBot

Type Parameters

TState

Type of the turnState. This allows for strongly typed access to the turn turnState.

Inheritance
Application<TState>
Implements

Remarks

The Application object replaces the traditional ActivityHandler that a bot would use. It supports a simpler fluent style of authoring bots versus the inheritance based approach used by the ActivityHandler class.

Additionally, it has built-in support for calling into the SDK's AI system and can be used to create bots that leverage Large Language Models (LLM) and other AI capabilities.

Constructors

Application<TState>(ApplicationOptions<TState>)

Creates a new Application instance.

Properties

Adapter

Fluent interface for accessing the bot adapter used to configure the application.

AdaptiveCards

Fluent interface for accessing Adaptive Card specific features.

AI

Fluent interface for accessing AI specific features.

Authentication

Accessing authentication specific features.

Meetings

Fluent interface for accessing Meetings' specific features.

MessageExtensions

Fluent interface for accessing Message Extensions' specific features.

Options

The application's configured options.

TaskModules

Fluent interface for accessing Task Modules' specific features.

Methods

AddRoute(RouteSelectorAsync, RouteHandler<TState>, Boolean)

Adds a new route to the application.

Developers won't typically need to call this method directly as it's used internally by all of the fluent interfaces to register routes for their specific activity types.

Routes will be matched in the order they're added to the application. The first selector to return true when an activity is received will have its handler called.

Invoke-based activities receive special treatment and are matched separately as they typically have shorter execution timeouts.

GetTokenOrStartSignInAsync(ITurnContext, TState, String, CancellationToken)

If the user is signed in, get the access token. If not, triggers the sign in flow for the provided authentication setting name and returns.In this case, the bot should end the turn until the sign in flow is completed.

OnActivity(MultipleRouteSelector, RouteHandler<TState>)

Handles incoming activities of a given type.

OnActivity(Regex, RouteHandler<TState>)

Handles incoming activities of a given type.

OnActivity(RouteSelectorAsync, RouteHandler<TState>)

Handles incoming activities of a given type.

OnActivity(String, RouteHandler<TState>)

Handles incoming activities of a given type.

OnAfterTurn(TurnEventHandlerAsync<TState>)

Add a handler that will execute after the turn's activity handler logic is processed.
Handler returns true to finish execution of the current turn. Handler returning false prevents the bots state from being saved.

OnBeforeTurn(TurnEventHandlerAsync<TState>)

Add a handler that will execute before the turn's activity handler logic is processed.
Handler returns true to continue execution of the current turn. Handler returning false prevents the turn from running, but the bots state is still saved, which lets you track the reason why the turn was not processed. It also means you can use this as a way to call into the dialog system. For example, you could use the OAuthPrompt to sign the user in before allowing the AI system to run.

OnConfigFetch(ConfigHandlerAsync<TState>)

Handles config fetch events for Microsoft Teams.

OnConfigSubmit(ConfigHandlerAsync<TState>)

Handles config submit events for Microsoft Teams.

OnConversationUpdate(String, RouteHandler<TState>)

Handles conversation update events.

OnConversationUpdate(String[], RouteHandler<TState>)

Handles conversation update events.

OnFileConsentAccept(FileConsentHandler<TState>)

Handles when a file consent card is accepted by the user.

OnFileConsentDecline(FileConsentHandler<TState>)

Handles when a file consent card is declined by the user.

OnMessage(MultipleRouteSelector, RouteHandler<TState>)

Handles incoming messages with a given keyword.
This method provides a simple way to have a bot respond anytime a user sends your bot a message with a specific word or phrase.

OnMessage(Regex, RouteHandler<TState>)

Handles incoming messages with a given keyword.
This method provides a simple way to have a bot respond anytime a user sends your bot a message with a specific word or phrase.
For example, you can easily clear the current conversation anytime a user sends "/reset":
application.OnMessage(new Regex("reset"), (context, turnState, _) => ...);

OnMessage(RouteSelectorAsync, RouteHandler<TState>)

Handles incoming messages with a given keyword.
This method provides a simple way to have a bot respond anytime a user sends your bot a message with a specific word or phrase.

OnMessage(String, RouteHandler<TState>)

Handles incoming messages with a given keyword.
This method provides a simple way to have a bot respond anytime a user sends your bot a message with a specific word or phrase.
For example, you can easily clear the current conversation anytime a user sends "/reset":
application.OnMessage("/reset", (context, turnState, _) => ...);

OnMessageDelete(RouteHandler<TState>)

Handles message soft delete events.

OnMessageEdit(RouteHandler<TState>)

Handles message edit events.

OnMessageReactionsAdded(RouteHandler<TState>)

Handles message reactions added events.

OnMessageReactionsRemoved(RouteHandler<TState>)

Handles message reactions removed events.

OnMessageUndelete(RouteHandler<TState>)

Handles message undo soft delete events.

OnO365ConnectorCardAction(O365ConnectorCardActionHandler<TState>)

Handles O365 Connector Card Action activities.

OnTeamsReadReceipt(ReadReceiptHandler<TState>)

Handles read receipt events for messages sent by the bot in personal scope.

OnTurnAsync(ITurnContext, CancellationToken)

Called by the adapter (for example, a CloudAdapter) at runtime in order to process an inbound Activity.

StartTypingTimer(ITurnContext)

Manually start a timer to periodically send "typing" activities.

StopTypingTimer()

Manually stop the typing timer.

Applies to