8000 Merge pull request #889 from microsoft/trboehre/typing-activityhandler · il-null-yuyi/botbuilder-python@5c726d4 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5c726d4

Browse files
authored
Merge pull request microsoft#889 from microsoft/trboehre/typing-activityhandler
Added ActivityHandler.on_typing_activity and tests.
2 parents 2305e20 + 40408fb commit 5c726d4

File tree

3 files changed

+81
-0
lines changed

3 files changed

+81
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ async def on_turn(self, turn_context: TurnContext):
8080
)
8181
elif turn_context.activity.type == ActivityTypes.end_of_conversation:
8282
await self.on_end_of_conversation_activity(turn_context)
83+
elif turn_context.activity.type == ActivityTypes.typing:
84+
await self.on_typing_activity(turn_context)
8385
else:
8486
await self.on_unrecognized_activity_type(turn_context)
8587

@@ -346,6 +348,19 @@ async def on_end_of_conversation_activity( # pylint: disable=unused-argument
346348
"""
347349
return
348350

351+
async def on_typing_activity( # pylint: disable=unused-argument
352+
self, turn_context: TurnContext
353+
):
354+
"""
355+
Override this in a derived class to provide logic specific to
356+
ActivityTypes.typing activities, such as the conversational logic.
357+
358+
:param turn_context: The context object for this turn
359+
:type turn_context: :class:`botbuilder.core.TurnContext`
360+
:returns: A task that represents the work queued to execute
361+
"""
362+
return
363+
349364
async def on_unrecognized_activity_type( # pylint: disable=unused-argument
350365
self, turn_context: TurnContext
351366
):

libraries/botbuilder-core/tests/teams/test_teams_activity_handler.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ async def on_event(self, turn_context: TurnContext):
5757
self.record.append("on_event")
5858
return await super().on_event(turn_context)
5959

60+
async def on_end_of_conversation_activity(self, turn_context: TurnContext):
61+
self.record.append("on_end_of_conversation_activity")
62+
return await super().on_end_of_conversation_activity(turn_context)
63+
64+
async def on_typing_activity(self, turn_context: TurnContext):
65+
self.record.append("on_typing_activity")
66+
return await super().on_typing_activity(turn_context)
67+
6068
async def on_unrecognized_activity_type(self, turn_context: TurnContext):
6169
self.record.append("on_unrecognized_activity_type")
6270
return await super().on_unrecognized_activity_type(turn_context)
@@ -724,3 +732,27 @@ async def test_on_teams_task_module_submit(self):
724732
assert len(bot.record) == 2
725733
assert bot.record[0] == "on_invoke_activity"
726734
assert bot.record[1] == "on_teams_task_module_submit"
735+
736+
async def test_on_end_of_conversation_activity(self):
737+
activity = Activity(type=ActivityTypes.end_of_conversation)
738+
739+
turn_context = TurnContext(SimpleAdapter(), activity)
740+
741+
# Act
742+
bot = TestingTeamsActivityHandler()
743+
await bot.on_turn(turn_context)
744+
745+
assert len(bot.record) == 1
746+
assert bot.record[0] == "on_end_of_conversation_activity"
747+
748+
async def test_typing_activity(self):
749+
activity = Activity(type=ActivityTypes.typing)
750+
751+
turn_context = TurnContext(SimpleAdapter(), activity)
752+
753+
# Act
754+
bot = TestingTeamsActivityHandler()
755+
await bot.on_turn(turn_context)
756+
757+
assert len(bot.record) == 1
758+
assert bot.record[0] == "on_typing_activity"

libraries/botbuilder-core/tests/test_activity_handler.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@ async def on_event(self, turn_context: TurnContext):
5959
self.record.append("on_event")
6060
return await super().on_event(turn_context)
6161

62+
async def on_end_of_conversation_activity(self, turn_context: TurnContext):
63+
self.record.append("on_end_of_conversation_activity")
64+
return await super().on_end_of_conversation_activity(turn_context)
65+
66+
async def on_typing_activity(self, turn_context: TurnContext):
67+
self.record.append("on_typing_activity")
68+
return await super().on_typing_activity(turn_context)
69+
6270
async def on_unrecognized_activity_type(self, turn_context: TurnContext):
6371
self.record.append("on_unrecognized_activity_type")
6472
return await super().on_unrecognized_activity_type(turn_context)
@@ -172,3 +180,29 @@ async def test_invoke_should_not_match(self):
172180
assert len(bot.record) == 1
173181
assert bot.record[0] == "on_invoke_activity"
174182
assert adapter.activity.value.status == int(HTTPStatus.NOT_IMPLEMENTED)
183+
184+
async def test_on_end_of_conversation_activity(self):
185+
activity = Activity(type=ActivityTypes.end_of_conversation)
186+
187+
adapter = TestInvokeAdapter()
188+
turn_context = TurnContext(adapter, activity)
189+
190+
# Act
191+
bot = TestingActivityHandler()
192+
await bot.on_turn(turn_context)
193+
194+
assert len(bot.record) == 1
195+
assert bot.record[0] == "on_end_of_conversation_activity"
196+
197+
async def test_typing_activity(self):
198+
activity = Activity(type=ActivityTypes.typing)
199+
200+
adapter = TestInvokeAdapter()
201+
turn_context = TurnContext(adapter, activity)
202+
203+
# Act
204+
bot = TestingActivityHandler()
205+
await bot.on_turn(turn_context)
206+
207+
assert len(bot.record) == 1
208+
assert bot.record[0] == "on_typing_activity"

0 commit comments

Comments
 (0)
0