Skip to content

Commit 265df6e

Browse files
Fixes some typing, updates attachments content
1 parent fec8704 commit 265df6e

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

src/sentry/notifications/platform/api/endpoints/internal_registered_templates.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from sentry.notifications.platform.email.provider import EmailRenderer
1313
from sentry.notifications.platform.msteams.provider import MSTeamsRenderable, MSTeamsRenderer
1414
from sentry.notifications.platform.registry import template_registry
15-
from sentry.notifications.platform.slack.provider import SlackRenderer
15+
from sentry.notifications.platform.slack.provider import SlackNotificationProvider
1616
from sentry.notifications.platform.types import (
1717
NotificationData,
1818
NotificationProviderKey,
@@ -92,13 +92,14 @@ def serialize_slack_preview[T: NotificationData](
9292
) -> dict[str, Any]:
9393
data = template.example_data
9494
rendered_template = template.render_example()
95-
message = SlackRenderer.render(data=data, rendered_template=rendered_template)
95+
renderer = SlackNotificationProvider.get_renderer(data=data, category=template.category)
96+
message = renderer.render(data=data, rendered_template=rendered_template)
9697

9798
serialized_blocks = []
9899
for block in message.get("blocks", []):
99100
serialized_blocks.append(block.to_dict())
100101

101-
return {"blocks": serialized_blocks}
102+
return {"blocks": serialized_blocks, "attachments": message.get("attachments", None)}
102103

103104

104105
def serialize_discord_preview[T: NotificationData](

src/sentry/notifications/platform/slack/provider.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__ import annotations
22

33
from dataclasses import dataclass
4-
from typing import TYPE_CHECKING, NotRequired, TypedDict
4+
from typing import TYPE_CHECKING, Any, NotRequired, TypedDict
55

66
from slack_sdk.models.blocks import (
77
ActionsBlock,
@@ -58,9 +58,8 @@ class SlackProviderThreadingContext(ProviderThreadingContext):
5858

5959
class SlackRenderable(TypedDict):
6060
blocks: list[Block]
61-
attachments: NotRequired[list[Block]]
61+
attachments: NotRequired[list[dict[str, Any]]]
6262
text: str
63-
color: NotRequired[str]
6463

6564

6665
class SlackRenderer(NotificationRenderer[SlackRenderable]):

src/sentry/notifications/platform/slack/renderers/metric_alert.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ def render[DataT: NotificationData](
4343
*blocks, fallback_text=fallback_text, color=color
4444
)
4545

46+
attachment_blocks = [
47+
{"blocks": slack_body.get("blocks", []), "color": slack_body.get("color", "")}
48+
]
49+
4650
renderable = SlackRenderable(
47-
blocks=slack_body.get("blocks", []),
48-
attachments=slack_body.get("attachments", []),
51+
blocks=[],
52+
attachments=attachment_blocks,
4953
text=slack_body.get("text", ""),
5054
)
51-
if (color := slack_body.get("color")) is not None:
52-
renderable["color"] = color
5355

5456
return renderable

src/sentry/notifications/platform/templates/metric_alert.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class MetricAlertNotificationData(NotificationData):
4242
@template_registry.register(NotificationSource.METRIC_ALERT)
4343
class MetricAlertNotificationTemplate(NotificationTemplate[MetricAlertNotificationData]):
4444
category = NotificationCategory.METRIC_ALERT
45-
hide_from_debugger = True
4645
example_data = MetricAlertNotificationData(
4746
group_id=1,
4847
organization_id=1,

0 commit comments

Comments
 (0)