1010from sentry .integrations .msteams .utils import get_user_conversation_id
1111from sentry .integrations .notifications import get_context , get_integrations_by_channel_by_recipient
1212from sentry .integrations .types import ExternalProviders
13- from sentry .models .team import Team
1413from sentry .notifications .notifications .activity .assigned import AssignedActivityNotification
14+ from sentry .notifications .notifications .activity .base import GroupActivityNotification
1515from sentry .notifications .notifications .activity .escalating import EscalatingActivityNotification
1616from sentry .notifications .notifications .activity .note import NoteActivityNotification
1717from sentry .notifications .notifications .activity .regression import RegressionActivityNotification
2525from sentry .notifications .notifications .rules import AlertRuleNotification
2626from sentry .notifications .notify import register_notification_provider
2727from sentry .types .actor import Actor
28- from sentry .users .models .user import User
2928from sentry .utils import metrics
3029
3130from .card_builder .notifications import (
4746 RegressionActivityNotification ,
4847 EscalatingActivityNotification ,
4948]
50- MESSAGE_BUILDERS = {
49+
50+ BASE_MESSAGE_BUILDERS = {
5151 "SlackNotificationsMessageBuilder" : MSTeamsNotificationsMessageBuilder ,
52+ }
53+
54+ # For Group-based notifications, it is possible we use a builder that is generic OR uses a group-specific builder
55+ GROUP_MESSAGE_BUILDERS = BASE_MESSAGE_BUILDERS | {
5256 "IssueNotificationMessageBuilder" : MSTeamsIssueNotificationsMessageBuilder ,
5357}
5458
@@ -62,10 +66,19 @@ def is_supported_notification_type(notification: BaseNotification) -> bool:
6266 )
6367
6468
65- def get_notification_card (
66- notification : BaseNotification , context : Mapping [str , Any ], recipient : User | Team | Actor
69+ def get_group_notification_card (
70+ notification : GroupActivityNotification | AlertRuleNotification ,
71+ context : Mapping [str , Any ],
72+ recipient : Actor ,
73+ ) -> AdaptiveCard :
74+ cls = GROUP_MESSAGE_BUILDERS [notification .message_builder ]
75+ return cls (notification , context , recipient ).build_notification_card ()
76+
77+
78+ def get_base_notification_card (
79+ notification : BaseNotification , context : Mapping [str , Any ], recipient : Actor
6780) -> AdaptiveCard :
68- cls = MESSAGE_BUILDERS [notification .message_builder ]
81+ cls = BASE_MESSAGE_BUILDERS [notification .message_builder ]
6982 return cls (notification , context , recipient ).build_notification_card ()
7083
7184
@@ -95,7 +108,12 @@ def send_notification_as_msteams(
95108 context = get_context (notification , recipient , shared_context , extra_context )
96109
97110 with sentry_sdk .start_span (op = "notification.send_msteams" , name = "gen_attachments" ):
98- card = get_notification_card (notification , context , recipient )
111+ if isinstance (notification , GroupActivityNotification ) or isinstance (
112+ notification , AlertRuleNotification
113+ ):
114+ card = get_group_notification_card (notification , context , recipient )
115+ else :
116+ card = get_base_notification_card (notification , context , recipient )
99117
100118 for channel , integration in integrations_by_channel .items ():
101119 conversation_id = get_user_conversation_id (integration , channel )
0 commit comments