Share via


ActivityHandler Class

Definition

An implementation of the IBot interface, intended for further subclassing.

public class ActivityHandler : Microsoft.Bot.Builder.IBot
type ActivityHandler = class
    interface IBot
Public Class ActivityHandler
Implements IBot
Inheritance
ActivityHandler
Derived
Implements

Remarks

Derive from this class to plug in code to handle particular activity types. Pre- and post-processing of Activity objects can be added by calling the base class implementation from the derived class.

Constructors

ActivityHandler()

Methods

CreateInvokeResponse(Object)

An InvokeResponse factory that initializes the body to the parameter passed and status equal to OK.

OnAdaptiveCardInvokeAsync(ITurnContext<IInvokeActivity>, AdaptiveCardInvokeValue, CancellationToken)

Invoked when the bot is sent an Adaptive Card Action Execute.

OnCommandActivityAsync(ITurnContext<ICommandActivity>, CancellationToken)

Invoked when a command activity is received when the base behavior of OnTurnAsync(ITurnContext, CancellationToken) is used. Commands are requests to perform an action and receivers typically respond with one or more commandResult activities. Receivers are also expected to explicitly reject unsupported command activities.

OnCommandResultActivityAsync(ITurnContext<ICommandResultActivity>, CancellationToken)

Invoked when a CommandResult activity is received when the base behavior of OnTurnAsync(ITurnContext, CancellationToken) is used. CommandResult activities can be used to communicate the result of a command execution.

OnConversationUpdateActivityAsync(ITurnContext<IConversationUpdateActivity>, CancellationToken)

Invoked when a conversation update activity is received from the channel when the base behavior of OnTurnAsync(ITurnContext, CancellationToken) is used. Conversation update activities are useful when it comes to responding to users being added to or removed from the conversation. For example, a bot could respond to a user being added by greeting the user. By default, this method will call OnMembersAddedAsync(IList<ChannelAccount>, ITurnContext<IConversationUpdateActivity>, CancellationToken) if any users have been added or OnMembersRemovedAsync(IList<ChannelAccount>, ITurnContext<IConversationUpdateActivity>, CancellationToken) if any users have been removed. The method checks the member ID so that it only responds to updates regarding members other than the bot itself.

OnEndOfConversationActivityAsync(ITurnContext<IEndOfConversationActivity>, CancellationToken)

Override this in a derived class to provide logic specific to EndOfConversation activities, such as the conversational logic.

OnEventActivityAsync(ITurnContext<IEventActivity>, CancellationToken)

Invoked when an event activity is received from the connector when the base behavior of OnTurnAsync(ITurnContext, CancellationToken) is used. Event activities can be used to communicate many different things. By default, this method will call OnTokenResponseEventAsync(ITurnContext<IEventActivity>, CancellationToken) if the activity's name is tokens/response or OnEventAsync(ITurnContext<IEventActivity>, CancellationToken) otherwise. A tokens/response event can be triggered by an OAuthCard.

OnEventAsync(ITurnContext<IEventActivity>, CancellationToken)

Invoked when an event other than tokens/response is received when the base behavior of OnEventActivityAsync(ITurnContext<IEventActivity>, CancellationToken) is used. This method could optionally be overridden if the bot is meant to handle miscellaneous events. By default, this method does nothing.

OnInstallationUpdateActivityAsync(ITurnContext<IInstallationUpdateActivity>, CancellationToken)

Override this in a derived class to provide logic specific to InstallationUpdate activities.

OnInstallationUpdateAddAsync(ITurnContext<IInstallationUpdateActivity>, CancellationToken)

Override this in a derived class to provide logic specific to InstallationUpdate activities with 'action' set to 'add'.

OnInstallationUpdateRemoveAsync(ITurnContext<IInstallationUpdateActivity>, CancellationToken)

Override this in a derived class to provide logic specific to InstallationUpdate activities with 'action' set to 'remove'.

OnInvokeActivityAsync(ITurnContext<IInvokeActivity>, CancellationToken)

Invoked when an invoke activity is received from the connector when the base behavior of OnTurnAsync(ITurnContext, CancellationToken) is used. Invoke activities can be used to communicate many different things. By default, this method will call OnSignInInvokeAsync(ITurnContext<IInvokeActivity>, CancellationToken) if the activity's name is signin/verifyState or signin/tokenExchange. A signin/verifyState or signin/tokenExchange invoke can be triggered by an OAuthCard.

OnMembersAddedAsync(IList<ChannelAccount>, ITurnContext<IConversationUpdateActivity>, CancellationToken)

Override this in a derived class to provide logic for when members other than the bot join the conversation, such as your bot's welcome logic.

OnMembersRemovedAsync(IList<ChannelAccount>, ITurnContext<IConversationUpdateActivity>, CancellationToken)

Override this in a derived class to provide logic for when members other than the bot leave the conversation, such as your bot's good-bye logic.

OnMessageActivityAsync(ITurnContext<IMessageActivity>, CancellationToken)

Override this in a derived class to provide logic specific to Message activities, such as the conversational logic.

OnMessageDeleteActivityAsync(ITurnContext<IMessageDeleteActivity>, CancellationToken)

Override this in a derived class to provide logic specific to MessageDelete activities, such as the conversational logic.

OnMessageReactionActivityAsync(ITurnContext<IMessageReactionActivity>, CancellationToken)

Invoked when an event activity is received from the connector when the base behavior of OnTurnAsync(ITurnContext, CancellationToken) is used. Message reactions correspond to the user adding a 'like' or 'sad' etc. (often an emoji) to a previously sent activity. Message reactions are only supported by a few channels. The activity that the message reaction corresponds to is indicated in the replyToId property. The value of this property is the activity id of a previously sent activity given back to the bot as the response from a send call.

OnMessageUpdateActivityAsync(ITurnContext<IMessageUpdateActivity>, CancellationToken)

Override this in a derived class to provide logic specific to MessageUpdate activities, such as the conversational logic.

OnReactionsAddedAsync(IList<MessageReaction>, ITurnContext<IMessageReactionActivity>, CancellationToken)

Override this in a derived class to provide logic for when reactions to a previous activity are added to the conversation.

OnReactionsRemovedAsync(IList<MessageReaction>, ITurnContext<IMessageReactionActivity>, CancellationToken)

Override this in a derived class to provide logic for when reactions to a previous activity are removed from the conversation.

OnSearchInvokeAsync(ITurnContext<IInvokeActivity>, SearchInvokeValue, CancellationToken)

Invoked when the bot is sent an 'invoke' activity having name of 'application/search'.

OnSignInInvokeAsync(ITurnContext<IInvokeActivity>, CancellationToken)

Invoked when a signin/verifyState or signin/tokenExchange event is received when the base behavior of OnInvokeActivityAsync(ITurnContext<IInvokeActivity>, CancellationToken) is used. If using an OAuthPrompt, override this method to forward this Activity to the current dialog. By default, this method does nothing.

OnTokenResponseEventAsync(ITurnContext<IEventActivity>, CancellationToken)

Invoked when a tokens/response event is received when the base behavior of OnEventActivityAsync(ITurnContext<IEventActivity>, CancellationToken) is used. If using an OAuthPrompt, override this method to forward this Activity to the current dialog. By default, this method does nothing.

OnTurnAsync(ITurnContext, CancellationToken)

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

OnTypingActivityAsync(ITurnContext<ITypingActivity>, CancellationToken)

Override this in a derived class to provide logic specific to Typing activities, such as the conversational logic.

OnUnrecognizedActivityTypeAsync(ITurnContext, CancellationToken)

Invoked when an activity other than a message, conversation update, or event is received when the base behavior of OnTurnAsync(ITurnContext, CancellationToken) is used. If overridden, this could potentially respond to any of the other activity types like ContactRelationUpdate or EndOfConversation. By default, this method does nothing.

Applies to