ActivityHandler Class

Handles activities and should be subclassed.

Inheritance
ActivityHandler

Constructor

ActivityHandler()

Remarks

Derive from this class to handle particular activity types. Yon can add pre and post processing of activities by calling the base class in the derived class.

Methods

on_adaptive_card_invoke

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

When the on_invoke_activity method receives an Invoke with a Activity.name of adaptiveCard/action, it calls this method.

on_conversation_update_activity

Invoked when a conversation update activity is received from the channel when the base behavior of on_turn is used.

on_end_of_conversation_activity

Invoked when a conversation end activity is received from the channel.

on_event

Invoked when an event other than tokens/response is received when the base behavior of on_event_activity is used.

on_event_activity

Invoked when an event activity is received from the connector when the base behavior of on_turn is used.

on_installation_update

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

on_installation_update_add

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

on_installation_update_remove

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

on_invoke_activity

Registers an activity event handler for the invoke event, emitted for every incoming event activity.

on_members_added_activity

Override this method in a derived class to provide logic for when members other than the bot join the conversation. You can add your bot's welcome logic.

conversation update activity :type members_added: List :param turn_context: The context object for this turn :type turn_context: TurnContext

on_members_removed_activity

Override this method in a derived class to provide logic for when members other than the bot leave the conversation. You can add your bot's good-bye logic.

conversation update activity :type members_added: List :param turn_context: The context object for this turn :type turn_context: TurnContext

on_message_activity

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

on_message_reaction_activity

Invoked when an event activity is received from the connector when the base behavior of on_turn is used.

on_reactions_added

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

on_reactions_removed

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

on_sign_in_invoke

Invoked when a signin/verifyState or signin/tokenExchange event is received when the base behavior of on_invoke_activity(TurnContext{InvokeActivity}) is used. If using an OAuthPrompt, override this method to forward this Activity"/ to the current dialog. By default, this method does nothing.

on_token_response_event

Invoked when a tokens/response event is received when the base behavior of on_event_activity is used. If using an oauth_prompt, override this method to forward this activity to the current dialog.

on_turn

Called by the adapter (for example, <xref:botbuilder.core.activity_handler.BotFrameworkAdapter>) at runtime in order to process an inbound Activity.

on_typing_activity

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

on_unrecognized_activity_type

Invoked when an activity other than a message, conversation update, or event is received when the base behavior of on_turn is used. If overridden, this method could potentially respond to any of the other activity types.

on_adaptive_card_invoke

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

When the on_invoke_activity method receives an Invoke with a Activity.name of adaptiveCard/action, it calls this method.

async on_adaptive_card_invoke(turn_context: TurnContext, invoke_value: AdaptiveCardInvokeValue) -> AdaptiveCardInvokeResponse

Parameters

Name Description
turn_context
Required

A context object for this turn.

invoke_value
Required
<xref:botframework.schema.models.AdaptiveCardInvokeValue>

A string-typed object from the incoming activity's value.

Returns

Type Description

The HealthCheckResponse object

on_conversation_update_activity

Invoked when a conversation update activity is received from the channel when the base behavior of on_turn is used.

async on_conversation_update_activity(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

Remarks

When the on_turn method receives a conversation update activity, it calls this method. Also

  • If the conversation update activity indicates that members other than the bot joined the conversation, it calls the on_members_added_activity method.
  • If the conversation update activity indicates that members other than the bot left the conversation, it calls the on_members_removed_activity method.
  • In a derived class, override this method to add logic that applies to all conversation update activities. Add logic to apply before the member added or removed logic before the call to this base class method.

on_end_of_conversation_activity

Invoked when a conversation end activity is received from the channel.

async on_end_of_conversation_activity(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

on_event

Invoked when an event other than tokens/response is received when the base behavior of on_event_activity is used.

async on_event(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

Remarks

When the on_event_activity is used method receives an event with an activity name other than tokens/response, it calls this method. This method could optionally be overridden if the bot is meant to handle miscellaneous events.

on_event_activity

Invoked when an event activity is received from the connector when the base behavior of on_turn is used.

async on_event_activity(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

Remarks

When the on_turn method receives an event activity, it calls this method. If the activity name is tokens/response, it calls on_token_response_event; otherwise, it calls on_event.

In a derived class, override this method to add logic that applies to all event activities. Add logic to apply before the specific event-handling logic before the call to this base class method. Add logic to apply after the specific event-handling logic after the call to this base class method.

Event activities communicate programmatic information from a client or channel to a bot. The meaning of an event activity is defined by the event activity name property, which is meaningful within the scope of a channel.

on_installation_update

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

async on_installation_update(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

on_installation_update_add

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

async on_installation_update_add(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

on_installation_update_remove

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

async on_installation_update_remove(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

on_invoke_activity

Registers an activity event handler for the invoke event, emitted for every incoming event activity.

async on_invoke_activity(turn_context: TurnContext) -> InvokeResponse | None

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

on_members_added_activity

Override this method in a derived class to provide logic for when members other than the bot join the conversation. You can add your bot's welcome logic.

conversation update activity :type members_added: List :param turn_context: The context object for this turn :type turn_context: TurnContext

async on_members_added_activity(members_added: List[ChannelAccount], turn_context: TurnContext)

Parameters

Name Description
members_added
Required
turn_context
Required

Returns

Type Description

A task that represents the work queued to execute

Remarks

When the on_conversation_update_activity method receives a conversation update activity that indicates one or more users other than the bot are joining the conversation, it calls this method.

on_members_removed_activity

Override this method in a derived class to provide logic for when members other than the bot leave the conversation. You can add your bot's good-bye logic.

conversation update activity :type members_added: List :param turn_context: The context object for this turn :type turn_context: TurnContext

async on_members_removed_activity(members_removed: List[ChannelAccount], turn_context: TurnContext)

Parameters

Name Description
members_removed
Required
turn_context
Required

Returns

Type Description

A task that represents the work queued to execute

Remarks

When the on_conversation_update_activity method receives a conversation update activity that indicates one or more users other than the bot are leaving the conversation, it calls this method.

on_message_activity

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

async on_message_activity(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

on_message_reaction_activity

Invoked when an event activity is received from the connector when the base behavior of on_turn is used.

async on_message_reaction_activity(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

Remarks

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 reply to Id 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. When the on_turn method receives a message reaction activity, it calls this method.

  • If the message reaction indicates that reactions were added to a message, it calls

<xref:botbuilder.core.activity_handler.ActivityHandler.on_reaction_added>.

  • If the message reaction indicates that reactions were removed from a message, it calls <xref:botbuilder.core.activity_handler.ActivityHandler.on_reaction_removed>.

In a derived class, override this method to add logic that applies to all message reaction activities. Add logic to apply before the reactions added or removed logic before the call to the this base class method. Add logic to apply after the reactions added or removed logic after the call to the this base class method.

on_reactions_added

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

async on_reactions_added(message_reactions: List[MessageReaction], turn_context: TurnContext)

Parameters

Name Description
message_reactions
Required

The list of reactions added

turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

Remarks

Message reactions correspond to the user adding a 'like' or 'sad' etc. (often an emoji) to a previously sent message on the conversation. Message reactions are supported by only a few channels. The activity that the message is in reaction to is identified by the activity's reply to ID property. The value of this property is the activity ID of a previously sent activity. When the bot sends an activity, the channel assigns an ID to it, which is available in the resource response Id of the result.

on_reactions_removed

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

async on_reactions_removed(message_reactions: List[MessageReaction], turn_context: TurnContext)

Parameters

Name Description
message_reactions
Required

The list of reactions removed

turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

Remarks

Message reactions correspond to the user adding a 'like' or 'sad' etc. (often an emoji) to a previously sent message on the conversation. Message reactions are supported by only a few channels. The activity that the message is in reaction to is identified by the activity's reply to Id property. The value of this property is the activity ID of a previously sent activity. When the bot sends an activity, the channel assigns an ID to it, which is available in the resource response Id of the result.

on_sign_in_invoke

Invoked when a signin/verifyState or signin/tokenExchange event is received when the base behavior of on_invoke_activity(TurnContext{InvokeActivity}) is used. If using an OAuthPrompt, override this method to forward this Activity"/ to the current dialog. By default, this method does nothing.

async on_sign_in_invoke(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

on_token_response_event

Invoked when a tokens/response event is received when the base behavior of on_event_activity is used. If using an oauth_prompt, override this method to forward this activity to the current dialog.

async on_token_response_event(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

Remarks

When the on_event method receives an event with an activity name of tokens/response, it calls this method. If your bot uses an oauth_prompt, forward the incoming activity to the current dialog.

on_turn

Called by the adapter (for example, <xref:botbuilder.core.activity_handler.BotFrameworkAdapter>) at runtime in order to process an inbound Activity.

async on_turn(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

Remarks

It calls other methods in this class based on the type of the activity to process, which allows a derived class to provide type-specific logic in a controlled way. In a derived class, override this method to add logic that applies to all activity types. Also

  • Add logic to apply before the type-specific logic and before calling on_turn.
  • Add logic to apply after the type-specific logic after calling on_turn.

on_typing_activity

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

async on_typing_activity(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

on_unrecognized_activity_type

Invoked when an activity other than a message, conversation update, or event is received when the base behavior of on_turn is used. If overridden, this method could potentially respond to any of the other activity types.

async on_unrecognized_activity_type(turn_context: TurnContext)

Parameters

Name Description
turn_context
Required

The context object for this turn

Returns

Type Description

A task that represents the work queued to execute

Remarks

When the on_turn method receives an activity that is not a message, conversation update, message reaction, or event activity, it calls this method.