|
11 | 11 | JsonValidator, |
12 | 12 | EnumValidator, |
13 | 13 | ) |
14 | | -from .basic_components import ButtonStyles |
| 14 | +from .basic_components import ButtonStyles, Workflow |
15 | 15 | from .basic_components import ConfirmObject |
16 | 16 | from .basic_components import DispatchActionConfig |
17 | 17 | from .basic_components import MarkdownTextObject |
@@ -1689,3 +1689,60 @@ def __init__( |
1689 | 1689 | @JsonValidator(f"options attribute must have between {options_min_length} " f"and {options_max_length} items") |
1690 | 1690 | def _validate_options_length(self) -> bool: |
1691 | 1691 | return self.options_min_length <= len(self.options) <= self.options_max_length |
| 1692 | + |
| 1693 | + |
| 1694 | +# ------------------------------------------------- |
| 1695 | +# Workflow Button |
| 1696 | +# ------------------------------------------------- |
| 1697 | + |
| 1698 | + |
| 1699 | +class WorkflowButtonElement(InteractiveElement): |
| 1700 | + type = "workflow_button" |
| 1701 | + |
| 1702 | + @property |
| 1703 | + def attributes(self) -> Set[str]: |
| 1704 | + return super().attributes.union({"text", "workflow", "style", "accessibility_label"}) |
| 1705 | + |
| 1706 | + def __init__( |
| 1707 | + self, |
| 1708 | + *, |
| 1709 | + text: Union[str, dict, TextObject], |
| 1710 | + action_id: Optional[str] = None, |
| 1711 | + workflow: Optional[Union[dict, Workflow]] = None, |
| 1712 | + style: Optional[str] = None, # primary, danger |
| 1713 | + accessibility_label: Optional[str] = None, |
| 1714 | + **others: dict, |
| 1715 | + ): |
| 1716 | + """Allows users to run a link trigger with customizable inputs |
| 1717 | + Interactive component - but interactions with workflow button elements will not send block_actions events, |
| 1718 | + since these are used to start new workflow runs. |
| 1719 | + https://api.slack.com/reference/block-kit/block-elements#workflow_button |
| 1720 | +
|
| 1721 | + Args: |
| 1722 | + text (required): A text object that defines the button's text. |
| 1723 | + Can only be of type: plain_text. text may truncate with ~30 characters. |
| 1724 | + Maximum length for the text in this field is 75 characters. |
| 1725 | + action_id (required): An identifier for this action. |
| 1726 | + You can use this when you receive an interaction payload to identify the source of the action. |
| 1727 | + Should be unique among all other action_ids in the containing block. |
| 1728 | + Maximum length for this field is 255 characters. |
| 1729 | + workflow: A workflow object that contains details about the workflow |
| 1730 | + that will run when the button is clicked. |
| 1731 | + style: Decorates buttons with alternative visual color schemes. Use this option with restraint. |
| 1732 | + "primary" gives buttons a green outline and text, ideal for affirmation or confirmation actions. |
| 1733 | + "primary" should only be used for one button within a set. |
| 1734 | + "danger" gives buttons a red outline and text, and should be used when the action is destructive. |
| 1735 | + Use "danger" even more sparingly than "primary". |
| 1736 | + If you don't include this field, the default button style will be used. |
| 1737 | + accessibility_label: A label for longer descriptive text about a button element. |
| 1738 | + This label will be read out by screen readers instead of the button text object. |
| 1739 | + Maximum length for this field is 75 characters. |
| 1740 | + """ |
| 1741 | + super().__init__(action_id=action_id, type=self.type) |
| 1742 | + show_unknown_key_warning(self, others) |
| 1743 | + |
| 1744 | + # NOTE: default_type=PlainTextObject.type here is only for backward-compatibility with version 2.5.0 |
| 1745 | + self.text = TextObject.parse(text, default_type=PlainTextObject.type) |
| 1746 | + self.workflow = workflow |
| 1747 | + self.style = style |
| 1748 | + self.accessibility_label = accessibility_label |
0 commit comments