Skip to content

Commit

Permalink
Support all possible fields for RichTextElementParts.Date (#1536)
Browse files Browse the repository at this point in the history
  • Loading branch information
srtaalej authored Aug 14, 2024
1 parent 98950d9 commit 1058da3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
8 changes: 7 additions & 1 deletion slack_sdk/models/blocks/block_elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -2099,17 +2099,23 @@ class Date(RichTextElement):

@property
def attributes(self) -> Set[str]:
return super().attributes.union({"timestamp"})
return super().attributes.union({"timestamp", "format", "url", "fallback"})

def __init__(
self,
*,
timestamp: str,
format: str,
url: Optional[str] = None,
fallback: Optional[str] = None,
**others: dict,
):
super().__init__(type=self.type)
show_unknown_key_warning(self, others)
self.timestamp = timestamp
self.format = format
self.url = url
self.fallback = fallback

class Broadcast(RichTextElement):
type = "broadcast"
Expand Down
25 changes: 25 additions & 0 deletions tests/slack_sdk/models/test_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,25 @@ def test_complex(self):
{"type": "usergroup", "usergroup_id": "S01BL602YLU"},
{"type": "text", "text": " "},
{"type": "channel", "channel_id": "C02GD0YEHDJ"},
{
"type": "date",
"timestamp": "1628633089",
"format": "{date_long}",
"url": "https://slack.com",
"fallback": "August 10, 2021",
},
{"type": "date", "timestamp": "1720710212", "format": "{date_num} at {time}", "fallback": "timey"},
{
"type": "date",
"timestamp": "1628633089",
"format": "{date_short_pretty}",
"url": "https://slack.com",
},
{
"type": "date",
"timestamp": "1628633089",
"format": "{ago}",
},
],
},
],
Expand Down Expand Up @@ -1078,6 +1097,12 @@ def test_complex(self):
_.UserGroup(usergroup_id="S01BL602YLU"),
_.Text(text=" "),
_.Channel(channel_id="C02GD0YEHDJ"),
_.Date(
timestamp="1628633089", format="{date_long}", url="https://slack.com", fallback="August 10, 2021"
),
_.Date(timestamp="1720710212", format="{date_num} at {time}", fallback="timey"),
_.Date(timestamp="1628633089", format="{date_short_pretty}", url="https://slack.com"),
_.Date(timestamp="1628633089", format="{ago}"),
]
),
],
Expand Down

0 comments on commit 1058da3

Please sign in to comment.