| 183 | |
| 184 | |
| 185 | class ButtonElement(InteractiveElement): |
| 186 | type = "button" |
| 187 | text_max_length = 75 |
| 188 | url_max_length = 3000 |
| 189 | value_max_length = 2000 |
| 190 | |
| 191 | @property |
| 192 | def attributes(self) -> Set[str]: # type: ignore[override] |
| 193 | return super().attributes.union({"text", "url", "value", "style", "confirm", "accessibility_label"}) |
| 194 | |
| 195 | def __init__( |
| 196 | self, |
| 197 | *, |
| 198 | text: Union[str, dict, TextObject], |
| 199 | action_id: Optional[str] = None, |
| 200 | url: Optional[str] = None, |
| 201 | value: Optional[str] = None, |
| 202 | style: Optional[str] = None, # primary, danger |
| 203 | confirm: Optional[Union[dict, ConfirmObject]] = None, |
| 204 | accessibility_label: Optional[str] = None, |
| 205 | **others: dict, |
| 206 | ): |
| 207 | """An interactive element that inserts a button. The button can be a trigger for |
| 208 | anything from opening a simple link to starting a complex workflow. |
| 209 | https://docs.slack.dev/reference/block-kit/block-elements/button-element/ |
| 210 | |
| 211 | Args: |
| 212 | text (required): A text object that defines the button's text. |
| 213 | Can only be of type: plain_text. |
| 214 | Maximum length for the text in this field is 75 characters. |
| 215 | action_id (required): An identifier for this action. |
| 216 | You can use this when you receive an interaction payload to identify the source of the action. |
| 217 | Should be unique among all other action_ids in the containing block. |
| 218 | Maximum length for this field is 255 characters. |
| 219 | url: A URL to load in the user's browser when the button is clicked. |
| 220 | Maximum length for this field is 3000 characters. |
| 221 | If you're using url, you'll still receive an interaction payload |
| 222 | and will need to send an acknowledgement response. |
| 223 | value: The value to send along with the interaction payload. |
| 224 | Maximum length for this field is 2000 characters. |
| 225 | style: Decorates buttons with alternative visual color schemes. Use this option with restraint. |
| 226 | "primary" gives buttons a green outline and text, ideal for affirmation or confirmation actions. |
| 227 | "primary" should only be used for one button within a set. |
| 228 | "danger" gives buttons a red outline and text, and should be used when the action is destructive. |
| 229 | Use "danger" even more sparingly than "primary". |
| 230 | If you don't include this field, the default button style will be used. |
| 231 | confirm: A confirm object that defines an optional confirmation dialog after the button is clicked. |
| 232 | accessibility_label: A label for longer descriptive text about a button element. |
| 233 | This label will be read out by screen readers instead of the button text object. |
| 234 | Maximum length for this field is 75 characters. |
| 235 | """ |
| 236 | super().__init__(action_id=action_id, type=self.type) |
| 237 | show_unknown_key_warning(self, others) |
| 238 | |
| 239 | # NOTE: default_type=PlainTextObject.type here is only for backward-compatibility with version 2.5.0 |
| 240 | self.text = TextObject.parse(text, default_type=PlainTextObject.type) |
| 241 | self.url = url |
| 242 | self.value = value |
no outgoing calls