diff --git a/slack/web/classes/objects.py b/slack/web/classes/objects.py index d87da33ba..e19a38b96 100644 --- a/slack/web/classes/objects.py +++ b/slack/web/classes/objects.py @@ -250,6 +250,7 @@ def __init__( text: Union[str, dict, TextObject], confirm: Union[str, dict, PlainTextObject] = "Yes", deny: Union[str, dict, PlainTextObject] = "No", + style: str = None, ): """ An object that defines a dialog that provides a confirmation step to any @@ -261,12 +262,14 @@ def __init__( self._text = TextObject.parse(text, default_type=MarkdownTextObject.type) self._confirm = TextObject.parse(confirm, default_type=PlainTextObject.type) self._deny = TextObject.parse(deny, default_type=PlainTextObject.type) + self._style = style # for backward-compatibility with version 2.0-2.5, the following fields return str values self.title = self._title.text if self._title else None self.text = self._text.text if self._text else None self.confirm = self._confirm.text if self._confirm else None self.deny = self._deny.text if self._deny else None + self.style = self._style @JsonValidator(f"title attribute cannot exceed {title_max_length} characters") def title_length(self): @@ -286,6 +289,10 @@ def confirm_length(self): def deny_length(self): return self._deny is None or len(self._deny.text) <= self.deny_max_length + @JsonValidator('style for confirm must be either "primary" or "danger"') + def _validate_confirm_style(self): + return self._style is None or self._style in ["primary", "danger"] + def to_dict(self, option_type: str = "block") -> dict: if option_type == "action": # deliberately skipping JSON validators here - can't find documentation @@ -315,6 +322,8 @@ def to_dict(self, option_type: str = "block") -> dict: json["confirm"] = self._confirm.to_dict() if self._deny: json["deny"] = self._deny.to_dict() + if self._style: + json["style"] = self._style return json diff --git a/tests/web/classes/test_objects.py b/tests/web/classes/test_objects.py index a9dea1a08..13ea887cd 100644 --- a/tests/web/classes/test_objects.py +++ b/tests/web/classes/test_objects.py @@ -476,3 +476,47 @@ def test_options_length(self): "text" ) + def test_confirm_style(self): + obj = ConfirmObject.parse({ + "title": { + "type": "plain_text", + "text": "Are you sure?" + }, + "text": { + "type": "mrkdwn", + "text": "Wouldn't you prefer a good game of _chess_?" + }, + "confirm": { + "type": "plain_text", + "text": "Do it" + }, + "deny": { + "type": "plain_text", + "text": "Stop, I've changed my mind!" + }, + "style": "primary" + }) + obj.validate_json() + self.assertEqual("primary", obj.style) + + def test_confirm_style_validation(self): + with self.assertRaises(SlackObjectFormationError): + ConfirmObject.parse({ + "title": { + "type": "plain_text", + "text": "Are you sure?" + }, + "text": { + "type": "mrkdwn", + "text": "Wouldn't you prefer a good game of _chess_?" + }, + "confirm": { + "type": "plain_text", + "text": "Do it" + }, + "deny": { + "type": "plain_text", + "text": "Stop, I've changed my mind!" + }, + "style": "something-wrong" + }).validate_json()