Skip to content

Commit b9b08cb

Browse files
authored
Merge branch 'master' into trboehre/appinsights
2 parents 6df2a36 + 8b5d8aa commit b9b08cb

File tree

4 files changed

+242
-1
lines changed

4 files changed

+242
-1
lines changed

libraries/botbuilder-core/botbuilder/core/teams/teams_activity_handler.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Copyright (c) Microsoft Corporation. All rights reserved.
22
# Licensed under the MIT License.
33

4+
# pylint: disable=too-many-lines
5+
46
from http import HTTPStatus
57
from botbuilder.schema import ChannelAccount, ErrorResponseException, SignInConstants
68
from botbuilder.core import ActivityHandler, InvokeResponse
@@ -510,6 +512,18 @@ async def on_conversation_update_activity(self, turn_context: TurnContext):
510512
return await self.on_teams_channel_renamed(
511513
channel_data.channel, channel_data.team, turn_context
512514
)
515+
if channel_data.event_type == "teamArchived":
516+
return await self.on_teams_team_archived(
517+
channel_data.team, turn_context
518+
)
519+
if channel_data.event_type == "teamDeleted":
520+
return await self.on_teams_team_deleted(
521+
channel_data.team, turn_context
522+
)
523+
if channel_data.event_type == "teamHardDeleted":
524+
return await self.on_teams_team_hard_deleted(
525+
channel_data.team, turn_context
526+
)
513527
if channel_data.event_type == "channelRestored":
514528
return await self.on_teams_channel_restored(
515529
channel_data.channel, channel_data.team, turn_context
@@ -518,6 +532,14 @@ async def on_conversation_update_activity(self, turn_context: TurnContext):
518532
return await self.on_teams_team_renamed_activity(
519533
channel_data.team, turn_context
520534
)
535+
if channel_data.event_type == "teamRestored":
536+
return await self.on_teams_team_restored(
537+
channel_data.team, turn_context
538+
)
539+
if channel_data.event_type == "teamUnarchived":
540+
return await self.on_teams_team_unarchived(
541+
channel_data.team, turn_context
542+
)
521543

522544
return await super().on_conversation_update_activity(turn_context)
523545

@@ -536,6 +558,48 @@ async def on_teams_channel_created( # pylint: disable=unused-argument
536558
"""
537559
return
538560

561+
async def on_teams_team_archived( # pylint: disable=unused-argument
562+
self, team_info: TeamInfo, turn_context: TurnContext
563+
):
564+
"""
565+
Invoked when a Team Archived event activity is received from the connector.
566+
Team Archived correspond to the user archiving a team.
567+
568+
:param team_info: The team info object representing the team.
569+
:param turn_context: A context object for this turn.
570+
571+
:returns: A task that represents the work queued to execute.
572+
"""
573+
return
574+
575+
async def on_teams_team_deleted( # pylint: disable=unused-argument
576+
self, team_info: TeamInfo, turn_context: TurnContext
577+
):
578+
"""
579+
Invoked when a Team Deleted event activity is received from the connector.
580+
Team Deleted corresponds to the user deleting a team.
581+
582+
:param team_info: The team info object representing the team.
583+
:param turn_context: A context object for this turn.
584+
585+
:returns: A task that represents the work queued to execute.
586+
"""
587+
return
588+
589+
async def on_teams_team_hard_deleted( # pylint: disable=unused-argument
590+
self, team_info: TeamInfo, turn_context: TurnContext
591+
):
592+
"""
593+
Invoked when a Team Hard Deleted event activity is received from the connector.
594+
Team Hard Deleted corresponds to the user hard deleting a team.
595+
596+
:param team_info: The team info object representing the team.
597+
:param turn_context: A context object for this turn.
598+
599+
:returns: A task that represents the work queued to execute.
600+
"""
601+
return
602+
539603
async def on_teams_team_renamed_activity( # pylint: disable=unused-argument
540604
self, team_info: TeamInfo, turn_context: TurnContext
541605
):
@@ -550,6 +614,34 @@ async def on_teams_team_renamed_activity( # pylint: disable=unused-argument
550614
"""
551615
return
552616

617+
async def on_teams_team_restored( # pylint: disable=unused-argument
618+
self, team_info: TeamInfo, turn_context: TurnContext
619+
):
620+
"""
621+
Invoked when a Team Restored event activity is received from the connector.
622+
Team Restored corresponds to the user restoring a team.
623+
624+
:param team_info: The team info object representing the team.
625+
:param turn_context: A context object for this turn.
626+
627+
:returns: A task that represents the work queued to execute.
628+
"""
629+
return
630+
631+
async def on_teams_team_unarchived( # pylint: disable=unused-argument
632+
self, team_info: TeamInfo, turn_context: TurnContext
633+
):
634+
"""
635+
Invoked when a Team Unarchived event activity is received from the connector.
636+
Team Unarchived correspond to the user unarchiving a team.
637+
638+
:param team_info: The team info object representing the team.
639+
:param turn_context: A context object for this turn.
640+
641+
:returns: A task that represents the work queued to execute.
642+
"""
643+
return
644+
553645
async def on_teams_members_added_dispatch( # pylint: disable=unused-argument
554646
self,
555647
members_added: [ChannelAccount],

libraries/botbuilder-core/botbuilder/core/telemetry_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
class TelemetryConstants:
66
"""Telemetry logger property names."""
77

8+
ATTACHMENTS_PROPERTY: str = "attachments"
89
CHANNEL_ID_PROPERTY: str = "channelId"
910
CONVERSATION_ID_PROPERTY: str = "conversationId"
1011
CONVERSATION_NAME_PROPERTY: str = "conversationName"

libraries/botbuilder-core/botbuilder/core/telemetry_logger_middleware.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,10 @@ async def fill_send_event_properties(
211211

212212
# Use the LogPersonalInformation flag to toggle logging PII data, text and user name are common examples
213213
if self.log_personal_information:
214+
if activity.attachments and activity.attachments.strip():
215+
properties[
216+
TelemetryConstants.ATTACHMENTS_PROPERTY
217+
] = activity.attachments
214218
if activity.from_property.name and activity.from_property.name.strip():
215219
properties[
216220
TelemetryConstants.FROM_NAME_PROPERTY

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

Lines changed: 145 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
from typing import List
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
# pylint: disable=too-many-lines
25

6+
from typing import List
37
import aiounittest
48
from botbuilder.core import BotAdapter, TurnContext
59
from botbuilder.core.teams import TeamsActivityHandler
@@ -116,12 +120,42 @@ async def on_teams_channel_deleted(
116120
channel_info, team_info, turn_context
117121
)
118122

123+
async def on_teams_team_archived(
124+
self, team_info: TeamInfo, turn_context: TurnContext
125+
):
126+
self.record.append("on_teams_team_archived")
127+
return await super().on_teams_team_archived(team_info, turn_context)
128+
129+
async def on_teams_team_deleted(
130+
self, team_info: TeamInfo, turn_context: TurnContext
131+
):
132+
self.record.append("on_teams_team_deleted")
133+
return await super().on_teams_team_deleted(team_info, turn_context)
134+
135+
async def on_teams_team_hard_deleted(
136+
self, team_info: TeamInfo, turn_context: TurnContext
137+
):
138+
self.record.append("on_teams_team_hard_deleted")
139+
return await super().on_teams_team_hard_deleted(team_info, turn_context)
140+
119141
async def on_teams_team_renamed_activity(
120142
self, team_info: TeamInfo, turn_context: TurnContext
121143
):
122144
self.record.append("on_teams_team_renamed_activity")
123145
return await super().on_teams_team_renamed_activity(team_info, turn_context)
124146

147+
async def on_teams_team_restored(
148+
self, team_info: TeamInfo, turn_context: TurnContext
149+
):
150+
self.record.append("on_teams_team_restored")
151+
return await super().on_teams_team_restored(team_info, turn_context)
152+
153+
async def on_teams_team_unarchived(
154+
self, team_info: TeamInfo, turn_context: TurnContext
155+
):
156+
self.record.append("on_teams_team_unarchived")
157+
return await super().on_teams_team_unarchived(team_info, turn_context)
158+
125159
async def on_invoke_activity(self, turn_context: TurnContext):
126160
self.record.append("on_invoke_activity")
127161
return await super().on_invoke_activity(turn_context)
@@ -365,6 +399,72 @@ async def test_on_teams_channel_deleted_activity(self):
365399
assert bot.record[0] == "on_conversation_update_activity"
366400
assert bot.record[1] == "on_teams_channel_deleted"
367401

402+
async def test_on_teams_team_archived(self):
403+
# arrange
404+
activity = Activity(
405+
type=ActivityTypes.conversation_update,
406+
channel_data={
407+
"eventType": "teamArchived",
408+
"team": {"id": "team_id_1", "name": "archived_team_name"},
409+
},
410+
channel_id=Channels.ms_teams,
411+
)
412+
413+
turn_context = TurnContext(NotImplementedAdapter(), activity)
414+
415+
# Act
416+
bot = TestingTeamsActivityHandler()
417+
await bot.on_turn(turn_context)
418+
419+
# Assert
420+
assert len(bot.record) == 2
421+
assert bot.record[0] == "on_conversation_update_activity"
422+
assert bot.record[1] == "on_teams_team_archived"
423+
424+
async def test_on_teams_team_deleted(self):
425+
# arrange
426+
activity = Activity(
427+
type=ActivityTypes.conversation_update,
428+
channel_data={
429+
"eventType": "teamDeleted",
430+
"team": {"id": "team_id_1", "name": "deleted_team_name"},
431+
},
432+
channel_id=Channels.ms_teams,
433+
)
434+
435+
turn_context = TurnContext(NotImplementedAdapter(), activity)
436+
437+
# Act
438+
bot = TestingTeamsActivityHandler()
439+
await bot.on_turn(turn_context)
440+
441+
# Assert
442+
assert len(bot.record) == 2
443+
assert bot.record[0] == "on_conversation_update_activity"
444+
assert bot.record[1] == "on_teams_team_deleted"
445+
446+
async def test_on_teams_team_hard_deleted(self):
447+
# arrange
448+
activity = Activity(
449+
type=ActivityTypes.conversation_update,
450+
channel_data={
451+
"eventType": "teamHardDeleted",
452+
"team": {"id": "team_id_1", "name": "hard_deleted_team_name"},
453+
},
454+
channel_id=Channels.ms_teams,
455+
)
456+
457+
turn_context = TurnContext(NotImplementedAdapter(), activity)
458+
459+
# Act
460+
bot = TestingTeamsActivityHandler()
461+
await bot.on_turn(turn_context)
462+
463+
# Assert
464+
assert len(bot.record) == 2
465+
assert bot.record[0] == "on_conversation_update_activity"
466+
assert bot.record[1] == "on_teams_team_hard_deleted"
467+
368468
async def test_on_teams_team_renamed_activity(self):
369469
# arrange
370470
activity = Activity(
@@ -387,6 +487,50 @@ async def test_on_teams_team_renamed_activity(self):
387487
assert bot.record[0] == "on_conversation_update_activity"
388488
assert bot.record[1] == "on_teams_team_renamed_activity"
389489

490+
async def test_on_teams_team_restored(self):
491+
# arrange
492+
activity = Activity(
493+
type=ActivityTypes.conversation_update,
494+
channel_data={
495+
"eventType": "teamRestored",
496+
"team": {"id": "team_id_1", "name": "restored_team_name"},
497+
},
498+
channel_id=Channels.ms_teams,
499+
)
500+
501+
turn_context = TurnContext(NotImplementedAdapter(), activity)
502+
503+
# Act
504+
bot = TestingTeamsActivityHandler()
505+
await bot.on_turn(turn_context)
506+
507+
# Assert
508+
assert len(bot.record) == 2
509+
assert bot.record[0] == "on_conversation_update_activity"
510+
assert bot.record[1] == "on_teams_team_restored"
511+
512+
async def test_on_teams_team_unarchived(self):
513+
# arrange
514+
activity = Activity(
515+
type=ActivityTypes.conversation_update,
516+
channel_data={
517+
"eventType": "teamUnarchived",
518+
"team": {"id": "team_id_1", "name": "unarchived_team_name"},
519+
},
520+
channel_id=Channels.ms_teams,
521+
)
522+
523+
turn_context = TurnContext(NotImplementedAdapter(), activity)
524+
525+
# Act
526+
bot = TestingTeamsActivityHandler()
527+
await bot.on_turn(turn_context)
528+
529+
# Assert
530+
assert len(bot.record) == 2
531+
assert bot.record[0] == "on_conversation_update_activity"
532+
assert bot.record[1] == "on_teams_team_unarchived"
533+
390534
async def test_on_teams_members_added_activity(self):
391535
# arrange
392536
activity = Activity(

0 commit comments

Comments
 (0)