10
10
from sentry .integrations .msteams .utils import get_user_conversation_id
11
11
from sentry .integrations .notifications import get_context , get_integrations_by_channel_by_recipient
12
12
from sentry .integrations .types import ExternalProviders
13
- from sentry .models .team import Team
14
13
from sentry .notifications .notifications .activity .assigned import AssignedActivityNotification
14
+ from sentry .notifications .notifications .activity .base import GroupActivityNotification
15
15
from sentry .notifications .notifications .activity .escalating import EscalatingActivityNotification
16
16
from sentry .notifications .notifications .activity .note import NoteActivityNotification
17
17
from sentry .notifications .notifications .activity .regression import RegressionActivityNotification
25
25
from sentry .notifications .notifications .rules import AlertRuleNotification
26
26
from sentry .notifications .notify import register_notification_provider
27
27
from sentry .types .actor import Actor
28
- from sentry .users .models .user import User
29
28
from sentry .utils import metrics
30
29
31
30
from .card_builder .notifications import (
47
46
RegressionActivityNotification ,
48
47
EscalatingActivityNotification ,
49
48
]
50
- MESSAGE_BUILDERS = {
49
+
50
+ BASE_MESSAGE_BUILDERS = {
51
51
"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 | {
52
56
"IssueNotificationMessageBuilder" : MSTeamsIssueNotificationsMessageBuilder ,
53
57
}
54
58
@@ -62,10 +66,19 @@ def is_supported_notification_type(notification: BaseNotification) -> bool:
62
66
)
63
67
64
68
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
67
80
) -> AdaptiveCard :
68
- cls = MESSAGE_BUILDERS [notification .message_builder ]
81
+ cls = BASE_MESSAGE_BUILDERS [notification .message_builder ]
69
82
return cls (notification , context , recipient ).build_notification_card ()
70
83
71
84
@@ -95,7 +108,12 @@ def send_notification_as_msteams(
95
108
context = get_context (notification , recipient , shared_context , extra_context )
96
109
97
110
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 )
99
117
100
118
for channel , integration in integrations_by_channel .items ():
101
119
conversation_id = get_user_conversation_id (integration , channel )
0 commit comments