8000 Merge pull request #1368 from microsoft/eric/addInstallationUpdateSub… · itsmokha/botbuilder-python@8970503 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8970503

Browse files
authored
Merge pull request microsoft#1368 from microsoft/eric/addInstallationUpdateSubEvents
Add installation update sub events to ActivityHandler
2 parents 4822b98 + 6319209 commit 8970503

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,36 @@ async def on_installation_update( # pylint: disable=unused-argument
374374
Override this in a derived class to provide logic specific to
375375
ActivityTypes.InstallationUpdate activities.
376376
377+
:param turn_context: The context object for this turn
378+
:type turn_context: :class:`botbuilder.core.TurnContext`
379+
:returns: A task that represents the work queued to execute
380+
"""
381+
if turn_context.activity.action == "add":
382+
return await self.on_installation_update_add(turn_context)
383+
if turn_context.activity.action == "remove":
384+
return await self.on_installation_update_remove(turn_context)
385+
return
386+
387+
async def on_installation_update_add( # pylint: disable=unused-argument
388+
self, turn_context: TurnContext
389+
):
390+
"""
391+
Override this in a derived class to provide logic specific to
392+
ActivityTypes.InstallationUpdate activities with 'action' set to 'add'.
393+
394+
:param turn_context: The context object for this turn
395+
:type turn_context: :class:`botbuilder.core.TurnContext`
396+
:returns: A task that represents the work queued to execute
397+
"""
398+
return
399+
400+
async def on_installation_update_remove( # pylint: disable=unused-argument
401+
self, turn_context: TurnContext
402+
):
403+
"""
404+
Override this in a derived class to provide logic specific to
405+
ActivityTypes.InstallationUpdate activities with 'action' set to 'remove'.
406+
377407
:param turn_context: The context object for this turn
378408
:type turn_context: :class:`botbuilder.core.TurnContext`
379409
:returns: A task that represents the work queued to execute

libraries/botbuilder-core/tests/test_activity_handler.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,14 @@ async def on_installation_update(self, turn_context: TurnContext):
7777
self.record.append("on_installation_update")
7878
return await super().on_installation_update(turn_context)
7979

80+
async def on_installation_update_add(self, turn_context: TurnContext):
81+
self.record.append("on_installation_update_add")
82+
return await super().on_installation_update_add(turn_context)
83+
84+
async def on_installation_update_remove(self, turn_context: TurnContext):
85+
self.record.append("on_installation_update_remove")
86+
return await super().on_installation_update_remove(turn_context)
87+
8088
async def on_unrecognized_activity_type(self, turn_context: TurnContext):
8189
self.record.append("on_unrecognized_activity_type")
8290
return await super().on_unrecognized_activity_type(turn_context)
@@ -246,6 +254,34 @@ async def test_on_installation_update(self):
246254
assert len(bot.record) == 1
247255
assert bot.record[0] == "on_installation_update"
248256

257+
async def test_on_installation_update_add(self):
258+
activity = Activity(type=ActivityTypes.installation_update, action="add")
259+
260+
adapter = TestInvokeAdapter()
261+
turn_context = TurnContext(adapter, activity)
262+
263+
# Act
264+
bot = TestingActivityHandler()
265+
await bot.on_turn(turn_context)
266+
267+
assert len(bot.record) == 2
268+
assert bot.record[0] == "on_installation_update"
269+
assert bot.record[1] == "on_installation_update_add"
270+
271+
async def test_on_installation_update_add_remove(self):
272+
activity = Activity(type=ActivityTypes.installation_update, action="remove")
273+
274+
adapter = TestInvokeAdapter()
275+
turn_context = TurnContext(adapter, activity)
276+
277+
# Act
278+
bot = TestingActivityHandler()
279+
await bot.on_turn(turn_context)
280+
281+
assert len(bot.record) == 2
282+
assert bot.record[0] == "on_installation_update"
283+
assert bot.record[1] == "on_installation_update_remove"
284+
249285
async def test_healthcheck(self):
250286
activity = Activity(type=ActivityTypes.invoke, name="healthcheck",)
251287

0 commit comments

Comments
 (0)
0