Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
fbe71ba
Test
Jan 10, 2020
43cec24
Update prompt.py (#591)
Jan 10, 2020
f6f69b7
Update conversation_state.py (#590)
Jan 10, 2020
8037ff2
Update conversation_state.py
Jan 13, 2020
98b47c7
Update prompt.py
Jan 13, 2020
bb83c82
Update oauth_prompt.py
Jan 14, 2020
9e24ae2
Update prompt_options.py
Jan 14, 2020
4d4ceb4
emolsh/api-ref-docs-dialogturnstatus
Jan 14, 2020
70ed08f
Update bot_state.py
Jan 15, 2020
d01d46b
Update bot_framework_adapter.py
Jan 16, 2020
4369918
Update bot_framework_adapter.py
Jan 16, 2020
8559317
emolsh/api-ref-docs-dialogreason
Jan 16, 2020
a334b6d
Fixed variable formatting
emgrol Jan 16, 2020
c824f4c
Fixed variable formatting
emgrol Jan 16, 2020
4a3ee84
emolsh/api-ref-docs-dialoginstance
Jan 16, 2020
e03f7e1
Update bot_framework_adapter.py
Jan 17, 2020
dc6108b
Update activity_handler.py
Jan 18, 2020
a136b9a
emolsh/api-ref-docs-dialogturnresult
Jan 20, 2020
2034c6b
emolsh/apu-ref-docs-dialogstate
Jan 20, 2020
161791e
Fixed formatting
emgrol Jan 20, 2020
8680347
Fixed formatting
emgrol Jan 20, 2020
84ebf41
Update dialog_instance.py
emgrol Jan 20, 2020
1ff4e09
Update activity_handler.py
Jan 21, 2020
feb1c5a
emolsh/api-ref-docs-activityprompt
Jan 21, 2020
ff0b5c3
Update activity_prompt.py
emgrol Jan 21, 2020
ee0ec47
Update activity_handler.py
Jan 22, 2020
31dc353
emolsh/api-ref-docs-componentdialog
Jan 22, 2020
6de1633
Updated formatting
emgrol Jan 22, 2020
e28409d
Updated formatting
emgrol Jan 22, 2020
00cb3a8
Updated formatting
emgrol Jan 22, 2020
bef0578
Updated formatting
emgrol Jan 22, 2020
299cec4
Updated formatting
emgrol Jan 22, 2020
c1cb806
Updated formatting
emgrol Jan 22, 2020
9759e56
Fixed formatting
emgrol Jan 24, 2020
695bd5d
Fixed formatting
emgrol Jan 24, 2020
ce58a6f
Fixed formatting
emgrol Jan 24, 2020
af0dc93
Fixed formatting
emgrol Jan 24, 2020
f75cffd
Update bot_state.py
Jan 24, 2020
7e72b0f
Fixed formatting
emgrol Jan 24, 2020
63ff981
Update activity_prompt.py
emgrol Jan 24, 2020
7426e9f
Fixed formatting
emgrol Jan 24, 2020
6b97814
Update conversation_state.py
Jan 24, 2020
f98a391
Update prompt.py
Jan 24, 2020
1a2cc75
Update bot_state.py
Jan 24, 2020
8703ddb
Update oauth_prompt.py
Jan 24, 2020
1a2e829
Update prompt.py
Jan 24, 2020
8fa2dee
Update prompt_options.py
Jan 24, 2020
526d2eb
Update bot_framework_adapter.py
Jan 25, 2020
5e36083
Update activity_handler.py
Jan 25, 2020
8bf73cc
Merge pull request #628 from microsoft/emolsh/api-ref-docs-activitypr…
tracyboehrer Jan 27, 2020
2217314
Merge pull request #632 from microsoft/emolsh/api-ref-docs-componentd…
tracyboehrer Jan 27, 2020
994df88
Merge pull request #621 from microsoft/emolsh/api-ref-docs-dialogstate
tracyboehrer Jan 27, 2020
50ac251
Merge pull request #620 from microsoft/emolsh/api-ref-docs-dialogturn…
tracyboehrer Jan 27, 2020
def0326
Merge pull request #616 from microsoft/emolsh/api-ref-docs-dialoginst…
tracyboehrer Jan 27, 2020
54b6729
Merge pull request #615 from microsoft/emolsh/api-ref-docs-dialogreason
tracyboehrer Jan 27, 2020
5d9441e
Merge pull request #605 from microsoft/emolsh/api-ref-docs-dialogturn…
tracyboehrer Jan 27, 2020
267afb8
Merge pull request #619 from microsoft/mm-api-ref-docs-activity-handler
tracyboehrer Jan 27, 2020
4450f3e
Merge pull request #613 from microsoft/mm-api-ref-docs-adapter
tracyboehrer Jan 27, 2020
9471670
Merge pull request #609 from microsoft/mm-api-ref-docs-bot-state
tracyboehrer Jan 27, 2020
516f723
Merge pull request #601 from microsoft/mm-api-ref-docs-prompt-options
tracyboehrer Jan 27, 2020
86c690d
Merge pull request #599 from microsoft/mm-api-ref-docs-oauth-prompt
tracyboehrer Jan 28, 2020
ff3e688
Merge pull request #598 from microsoft/mm-api-ref-docs-prompt
tracyboehrer Jan 28, 2020
29b5736
Merge pull request #597 from microsoft/mm-api-ref-docs-conversationstate
tracyboehrer Jan 28, 2020
33bc1a7
Fixed formatting
Jan 28, 2020
a9b37ec
FIxed pylint errors
tracyboehrer Jan 28, 2020
9f722d2
pylint corrections in dialogs
tracyboehrer Jan 28, 2020
60a274d
pylint corrections in core
tracyboehrer Jan 28, 2020
84785d9
Merge branch 'master' into python-API-ref-docs
tracyboehrer Jan 28, 2020
fd0059a
black corrections
tracyboehrer Jan 28, 2020
cecc07c
Merge branch 'master' into python-API-ref-docs
tracyboehrer Jan 28, 2020
5a6e6fb
Merge branch 'python-API-ref-docs' of https://github.com/microsoft/bo…
tracyboehrer Jan 28, 2020
a68c5e8
More pylint corrections
tracyboehrer Jan 28, 2020
5685d77
ConversationState pylint
tracyboehrer Jan 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
219 changes: 219 additions & 0 deletions libraries/botbuilder-core/botbuilder/core/activity_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@

class ActivityHandler:
async def on_turn(self, turn_context: TurnContext):
"""
Called by the adapter (for example, :class:`BotFrameworkAdapter`) at runtime
in order to process an inbound :class:`botbuilder.schema.Activity`.

:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: 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.

.. note::
- Add logic to apply before the type-specific logic and before the call to the
:meth:`ActivityHandler.on_turn()` method.
- Add logic to apply after the type-specific logic after the call to the
:meth:`ActivityHandler.on_turn()` method.
"""
if turn_context is None:
raise TypeError("ActivityHandler.on_turn(): turn_context cannot be None.")

Expand Down Expand Up @@ -40,9 +60,38 @@ async def on_turn(self, turn_context: TurnContext):
async def on_message_activity( # pylint: disable=unused-argument
self, turn_context: TurnContext
):
"""
Override this method in a derived class to provide logic specific to activities,
such as the conversational logic.

:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

"""
return

async def on_conversation_update_activity(self, turn_context: TurnContext):
"""
Invoked when a conversation update activity is received from the channel when the base behavior of
:meth:`ActivityHandler.on_turn()` is used.

:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
When the :meth:'ActivityHandler.on_turn()` method receives a conversation update activity, it calls this
method.
If the conversation update activity indicates that members other than the bot joined the conversation,
it calls the :meth:`ActivityHandler.on_members_added_activity()` method.
If the conversation update activity indicates that members other than the bot left the conversation,
it calls the :meth:`ActivityHandler.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.
"""
if (
turn_context.activity.members_added is not None
and turn_context.activity.members_added
Expand All @@ -62,14 +111,75 @@ async def on_conversation_update_activity(self, turn_context: TurnContext):
async def on_members_added_activity(
self, members_added: List[ChannelAccount], turn_context: TurnContext
): # pylint: disable=unused-argument
"""
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.

:param members_added: A list of all the members added to the conversation, as described by the
conversation update activity
:type members_added: :class:`typing.List`
:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
When the :meth:'ActivityHandler.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.
"""
return

async def on_members_removed_activity(
self, members_removed: List[ChannelAccount], turn_context: TurnContext
): # pylint: disable=unused-argument
"""
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.

:param members_added: A list of all the members removed from the conversation, as described by the
conversation update activity
:type members_added: :class:`typing.List`
:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
When the :meth:'ActivityHandler.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.
"""

return

async def on_message_reaction_activity(self, turn_context: TurnContext):
"""
Invoked when an event activity is received from the connector when the base behavior of
:meth:'ActivityHandler.on_turn()` is used.

:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
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 :meth:'ActivityHandler.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
:meth:'ActivityHandler.on_reaction_added().
If the message reaction indicates that reactions were removed from a message, it calls
:meth:'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.
"""
if turn_context.activity.reactions_added is not None:
await self.on_reactions_added(
turn_context.activity.reactions_added, turn_context
Expand All @@ -83,14 +193,72 @@ async def on_message_reaction_activity(self, turn_context: TurnContext):
async def on_reactions_added( # pylint: disable=unused-argument
self, message_reactions: List[MessageReaction], turn_context: TurnContext
):
"""
Override this method in a derived class to provide logic for when reactions to a previous activity
are added to the conversation.

:param message_reactions: The list of reactions added
:type message_reactions: :class:`typing.List`
:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
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.
"""
return

async def on_reactions_removed( # pylint: disable=unused-argument
self, message_reactions: List[MessageReaction], turn_context: TurnContext
):
"""
Override this method in a derived class to provide logic for when reactions to a previous activity
are removed from the conversation.

:param message_reactions: The list of reactions removed
:type message_reactions: :class:`typing.List`
:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
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.
"""
return

async def on_event_activity(self, turn_context: TurnContext):
"""
Invoked when an event activity is received from the connector when the base behavior of
:meth:'ActivityHandler.on_turn()` is used.

:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
When the :meth:'ActivityHandler.on_turn()` method receives an event activity, it calls this method.
If the activity name is `tokens/response`, it calls :meth:'ActivityHandler.on_token_response_event()`;
otherwise, it calls :meth:'ActivityHandler.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.
"""
if turn_context.activity.name == "tokens/response":
return await self.on_token_response_event(turn_context)

Expand All @@ -99,19 +267,70 @@ async def on_event_activity(self, turn_context: TurnContext):
async def on_token_response_event( # pylint: disable=unused-argument
self, turn_context: TurnContext
):
"""
Invoked when a `tokens/response` event is received when the base behavior of
:meth:'ActivityHandler.on_event_activity()` is used.
If using an `oauth_prompt`, override this method to forward this activity to the current dialog.

:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
When the :meth:'ActivityHandler.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.
"""
return

async def on_event( # pylint: disable=unused-argument
self, turn_context: TurnContext
):
"""
Invoked when an event other than `tokens/response` is received when the base behavior of
:meth:'ActivityHandler.on_event_activity()` is used.


:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
When the :meth:'ActivityHandler.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.
"""
return

async def on_end_of_conversation_activity( # pylint: disable=unused-argument
self, turn_context: TurnContext
):
"""
Invoked when a conversation end activity is received from the channel.

:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`
:returns: A task that represents the work queued to execute
"""
return

async def on_unrecognized_activity_type( # pylint: disable=unused-argument
self, turn_context: TurnContext
):
"""
Invoked when an activity other than a message, conversation update, or event is received when the base
behavior of :meth:`ActivityHandler.on_turn()` is used.
If overridden, this method could potentially respond to any of the other activity types.

:param turn_context: The context object for this turn
:type turn_context: :class:`TurnContext`

:returns: A task that represents the work queued to execute

.. note::
When the :meth:`ActivityHandler.on_turn()` method receives an activity that is not a message,
conversation update, message reaction, or event activity, it calls this method.
"""
return
Loading