Skip to content

Commit ee0ec47

Browse files
author
Michael Miele
committed
Update activity_handler.py
Added remaining ref doc
1 parent 1ff4e09 commit ee0ec47

File tree

1 file changed

+150
-10
lines changed

1 file changed

+150
-10
lines changed

libraries/botbuilder-core/botbuilder/core/activity_handler.py

Lines changed: 150 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ async def on_turn(self, turn_context: TurnContext):
2222
In a derived class, override this method to add logic that applies to all activity types.
2323
2424
.. note::
25-
- Add logic to apply before the type-specific logic and before the call to the base class `OnTurnAsync` method.
26-
- Add logic to apply after the type-specific logic after the call to the base class `OnTurnAsync` method.
25+
- Add logic to apply before the type-specific logic and before the call to the :meth:`ActivityHandler.on_turn()` method.
26+
- Add logic to apply after the type-specific logic after the call to the :meth:`ActivityHandler.on_turn()` method.
2727
"""
2828
if turn_context is None:
2929
raise TypeError("ActivityHandler.on_turn(): turn_context cannot be None.")
@@ -69,13 +69,7 @@ async def on_message_activity( # pylint: disable=unused-argument
6969
return
7070

7171
async def on_conversation_update_activity(self, turn_context: TurnContext):
72-
"""Invoked when a conversation update activity is received from the channel when the base behavior of
73-
`OnTurnAsync` is used.
74-
Conversation update activities are useful when it comes to responding to users being added to or removed from the conversation.
75-
For example, a bot could respond to a user being added by greeting the user.
76-
By default, this method calls :meth:`ActivityHandler.on_members_added_activity()` if any users have been added or
77-
:meth:`ActivityHandler.on_members_removed_activity()` if any users have been removed.
78-
The method checks the member ID so that it only responds to updates regarding members other than the bot itself.
72+
"""Invoked when a conversation update activity is received from the channel when the base behavior of :meth:`ActivityHandler.on_turn()` is used.
7973
8074
:param turn_context: The context object for this turn
8175
:type turn_context: :class:`TurnContext`
@@ -108,15 +102,63 @@ async def on_conversation_update_activity(self, turn_context: TurnContext):
108102

109103
async def on_members_added_activity(
110104
self, members_added: List[ChannelAccount], turn_context: TurnContext
111-
): # pylint: disable=unused-argument
105+
): # pylint: disable=unused-argument
106+
"""Override this method in a derived class to provide logic for when members other than the bot join the conversation.
107+
You can add your bot's welcome logic.
108+
109+
:param members_added: A list of all the members added to the conversation, as described by the conversation update activity
110+
:type members_added: :class:`typing.List`
111+
:param turn_context: The context object for this turn
112+
:type turn_context: :class:`TurnContext`
113+
114+
:returns: A task that represents the work queued to execute
115+
116+
.. remarks::
117+
When the :meth:'ActivityHandler.on_conversation_update_activity()` method receives a conversation update activity that indicates
118+
one or more users other than the bot are joining the conversation, it calls this method.
119+
"""
112120
return
113121

114122
async def on_members_removed_activity(
115123
self, members_removed: List[ChannelAccount], turn_context: TurnContext
116124
): # pylint: disable=unused-argument
125+
"""Override this method in a derived class to provide logic for when members other than the bot leave the conversation.
126+
You can add your bot's good-bye logic.
127+
128+
:param members_added: A list of all the members removed from the conversation, as described by the conversation update activity
129+
:type members_added: :class:`typing.List`
130+
:param turn_context: The context object for this turn
131+
:type turn_context: :class:`TurnContext`
132+
133+
:returns: A task that represents the work queued to execute
134+
135+
.. remarks::
136+
When the :meth:'ActivityHandler.on_conversation_update_activity()` method receives a conversation update activity that indicates
137+
one or more users other than the bot are leaving the conversation, it calls this method.
138+
"""
139+
117140
return
118141

119142
async def on_message_reaction_activity(self, turn_context: TurnContext):
143+
"""Invoked when an event activity is received from the connector when the base behavior of :meth:'ActivityHandler.on_turn()` is used.
144+
Message reactions correspond to the user adding a 'like' or 'sad' etc. (often an emoji) to a previously sent activity.
145+
Message reactions are only supported by a few channels. The activity that the message reaction corresponds to is indicated in the
146+
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
147+
from a send call.
148+
149+
:param turn_context: The context object for this turn
150+
:type turn_context: :class:`TurnContext`
151+
152+
:returns: A task that represents the work queued to execute
153+
154+
.. remarks::
155+
When the :meth:'ActivityHandler.on_turn()` method receives a message reaction activity, it calls this method.
156+
If the message reaction indicates that reactions were added to a message, it calls :meth:'ActivityHandler.on_reaction_added().
157+
If the message reaction indicates that reactions were removed from a message, it calls :meth:'ActivityHandler.on_reaction_removed().
158+
In a derived class, override this method to add logic that applies to all message reaction activities.
159+
Add logic to apply before the reactions added or removed logic before the call to the this base class method.
160+
Add logic to apply after the reactions added or removed logic after the call to the this base class method.
161+
"""
120162
if turn_context.activity.reactions_added is not None:
121163
await self.on_reactions_added(
122164
turn_context.activity.reactions_added, turn_context
@@ -130,14 +172,68 @@ async def on_message_reaction_activity(self, turn_context: TurnContext):
130172
async def on_reactions_added( # pylint: disable=unused-argument
131173
self, message_reactions: List[MessageReaction], turn_context: TurnContext
132174
):
175+
"""Override this method in a derived class to provide logic for when reactions to a previous activity
176+
are added to the conversation.
177+
178+
:param message_reactions: The list of reactions added
179+
:type message_reactions: :class:`typing.List`
180+
:param turn_context: The context object for this turn
181+
:type turn_context: :class:`TurnContext`
182+
183+
:returns: A task that represents the work queued to execute
184+
185+
.. remarks::
186+
Message reactions correspond to the user adding a 'like' or 'sad' etc. (often an emoji)
187+
to a previously sent message on the conversation. Message reactions are supported by only a few channels.
188+
The activity that the message is in reaction to is identified by the activity's reply to Id property.
189+
The value of this property is the activity ID of a previously sent activity. When the bot sends an activity,
190+
the channel assigns an ID to it, which is available in the resource response Id of the result.
191+
"""
133192
return
134193

135194
async def on_reactions_removed( # pylint: disable=unused-argument
136195
self, message_reactions: List[MessageReaction], turn_context: TurnContext
137196
):
197+
"""Override this method in a derived class to provide logic for when reactions to a previous activity
198+
are removed from the conversation.
199+
200+
:param message_reactions: The list of reactions removed
201+
:type message_reactions: :class:`typing.List`
202+
:param turn_context: The context object for this turn
203+
:type turn_context: :class:`TurnContext`
204+
205+
:returns: A task that represents the work queued to execute
206+
207+
.. remarks::
208+
Message reactions correspond to the user adding a 'like' or 'sad' etc. (often an emoji)
209+
to a previously sent message on the conversation. Message reactions are supported by only a few channels.
210+
The activity that the message is in reaction to is identified by the activity's reply to Id property.
211+
The value of this property is the activity ID of a previously sent activity. When the bot sends an activity,
212+
the channel assigns an ID to it, which is available in the resource response Id of the result.
213+
"""
138214
return
139215

140216
async def on_event_activity(self, turn_context: TurnContext):
217+
"""Invoked when an event activity is received from the connector when the base behavior of :meth:'ActivityHandler.on_turn()` is used.
218+
219+
:param turn_context: The context object for this turn
220+
:type turn_context: :class:`TurnContext`
221+
222+
:returns: A task that represents the work queued to execute
223+
224+
.. remarks::
225+
When the :meth:'ActivityHandler.on_turn()` method receives an event activity, it calls this method.
226+
If the activity name is `tokens/response`, it calls :meth:'ActivityHandler.on_token_response_event()`;
227+
otherwise, it calls :meth:'ActivityHandler.on_event()`.
228+
229+
In a derived class, override this method to add logic that applies to all event activities.
230+
Add logic to apply before the specific event-handling logic before the call to this base class method.
231+
Add logic to apply after the specific event-handling logic after the call to this base class method.
232+
233+
Event activities communicate programmatic information from a client or channel to a bot.
234+
The meaning of an event activity is defined by the event activity name property, which is meaningful within
235+
the scope of a channel.
236+
"""
141237
if turn_context.activity.name == "tokens/response":
142238
return await self.on_token_response_event(turn_context)
143239

@@ -146,19 +242,63 @@ async def on_event_activity(self, turn_context: TurnContext):
146242
async def on_token_response_event( # pylint: disable=unused-argument
147243
self, turn_context: TurnContext
148244
):
245+
"""Invoked when a `tokens/response` event is received when the base behavior of :meth:'ActivityHandler.on_event_activity()` is used.
246+
If using an `oauth_prompt`, override this method to forward this activity to the current dialog.
247+
248+
:param turn_context: The context object for this turn
249+
:type turn_context: :class:`TurnContext`
250+
251+
:returns: A task that represents the work queued to execute
252+
253+
.. remarks::
254+
When the :meth:'ActivityHandler.on_event()` method receives an event with an activity name of `tokens/response`,
255+
it calls this method. If your bot uses an `oauth_prompt`, forward the incoming activity to the current dialog.
256+
"""
149257
return
150258

151259
async def on_event( # pylint: disable=unused-argument
152260
self, turn_context: TurnContext
153261
):
262+
"""Invoked when an event other than `tokens/response` is received when the base behavior of
263+
:meth:'ActivityHandler.on_event_activity()` is used.
264+
This method could optionally be overridden if the bot is meant to handle miscellaneous events.
265+
266+
:param turn_context: The context object for this turn
267+
:type turn_context: :class:`TurnContext`
268+
269+
:returns: A task that represents the work queued to execute
270+
271+
.. remarks::
272+
When the :meth:'ActivityHandler.on_event_activity()` is used method receives an event with an
273+
activity name other than `tokens/response`, it calls this method.
274+
"""
154275
return
155276

156277
async def on_end_of_conversation_activity( # pylint: disable=unused-argument
157278
self, turn_context: TurnContext
158279
):
280+
"""Invoked when a conversation end activity is received from the channel.
281+
282+
:param turn_context: The context object for this turn
283+
:type turn_context: :class:`TurnContext`
284+
:returns: A task that represents the work queued to execute
285+
"""
159286
return
160287

161288
async def on_unrecognized_activity_type( # pylint: disable=unused-argument
162289
self, turn_context: TurnContext
163290
):
291+
"""Invoked when an activity other than a message, conversation update, or event is received when the base behavior of
292+
:meth:`ActivityHandler.on_turn()` is used.
293+
If overridden, this method could potentially respond to any of the other activity types.
294+
295+
:param turn_context: The context object for this turn
296+
:type turn_context: :class:`TurnContext`
297+
298+
:returns: A task that represents the work queued to execute
299+
300+
.. remarks::
301+
When the :meth:`ActivityHandler.on_turn()` method receives an activity that is not a message, conversation update, message reaction,
302+
or event activity, it calls this method.
303+
"""
164304
return

0 commit comments

Comments
 (0)