|
7 | 7 |
|
8 | 8 | from elementary.config.config import Config |
9 | 9 | from elementary.messages.block_builders import TextLineBlock |
10 | | -from elementary.messages.blocks import HeaderBlock, LinesBlock |
11 | | -from elementary.messages.message_body import MessageBody |
| 10 | +from elementary.messages.blocks import ( |
| 11 | + HeaderBlock, |
| 12 | + LineBlock, |
| 13 | + LinesBlock, |
| 14 | + LinkBlock, |
| 15 | + TextBlock, |
| 16 | +) |
| 17 | +from elementary.messages.message_body import MessageBlock, MessageBody |
12 | 18 | from elementary.messages.messaging_integrations.base_messaging_integration import ( |
13 | 19 | BaseMessagingIntegration, |
14 | 20 | MessageSendResult, |
@@ -57,6 +63,37 @@ def get_health_check_message() -> MessageBody: |
57 | 63 | ) |
58 | 64 |
|
59 | 65 |
|
| 66 | +def _add_elementary_attribution(body: MessageBody) -> MessageBody: |
| 67 | + lines = [ |
| 68 | + LineBlock( |
| 69 | + inlines=[ |
| 70 | + TextBlock(text="Powered by"), |
| 71 | + LinkBlock( |
| 72 | + text="Elementary", |
| 73 | + url="https://www.elementary-data.com/", |
| 74 | + ), |
| 75 | + ] |
| 76 | + ) |
| 77 | + ] |
| 78 | + attribution_block = LinesBlock( |
| 79 | + lines=lines, |
| 80 | + ) |
| 81 | + |
| 82 | + new_blocks: List[MessageBlock] = [] |
| 83 | + first_block_is_header = body.blocks and isinstance(body.blocks[0], HeaderBlock) |
| 84 | + if first_block_is_header: |
| 85 | + new_blocks = [body.blocks[0], attribution_block, *body.blocks[1:]] |
| 86 | + else: |
| 87 | + new_blocks = [*body.blocks, attribution_block] |
| 88 | + |
| 89 | + body_with_attribution = MessageBody( |
| 90 | + blocks=new_blocks, |
| 91 | + color=body.color, |
| 92 | + id=body.id, |
| 93 | + ) |
| 94 | + return body_with_attribution |
| 95 | + |
| 96 | + |
60 | 97 | class DataMonitoringAlerts(DataMonitoring): |
61 | 98 | alerts_integration: Union[BaseMessagingIntegration, BaseIntegration] |
62 | 99 |
|
@@ -313,6 +350,7 @@ def _send_alert( |
313 | 350 | alert_message_body = alert_message_builder.build( |
314 | 351 | alert=alert, |
315 | 352 | ) |
| 353 | + alert_message_body = _add_elementary_attribution(alert_message_body) |
316 | 354 | try: |
317 | 355 | self._send_message( |
318 | 356 | integration=self.alerts_integration, |
|
0 commit comments