Skip to content

Elements

Elements are interactive UI controls that go inside blocks — buttons, select menus, date pickers, text inputs, and so on. They're typically embedded in a SectionBlock (as an accessory), an ActionsBlock (as one of several elements), or an InputBlock (as the input control).

Many elements take Option or ConfirmationDialogue objects as parameters — see Objects.

Slack reference: https://api.slack.com/reference/block-kit/block-elements

Block elements can be used inside of section, context, input, and actions layout blocks.

See: https://api.slack.com/reference/block-kit/block-elements

ButtonStyleName module-attribute

ButtonStyleName = Literal['primary', 'danger']

The string-valued style accepted by Button and WorkflowButton. Equivalent to using ButtonStyle.PRIMARY / ButtonStyle.DANGER.

Button

An interactive element that inserts a button. The button can be a trigger for anything from opening a simple link to starting a complex workflow.

See: https://api.slack.com/reference/block-kit/block-elements#button.

Parameters:

Name Type Description Default
text TextLike

text on the button (plaintext only; max 75 chars).

required
action_id str

an identifier so the source of the action can be known.

required
url str | None

a URL to load in the user's browser when the button is clicked.

None
value str | None

the value sent with the interaction payload.

None
style ButtonStyle | ButtonStyleName | None

the visual style of the button, one of primary, danger.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the button is clicked.

None
accessibility_label str | None

a string label for longer descriptive text about a button element. Used by screen readers (max 75 chars).

None

Throws: InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
class Button(Element):
    """
    An interactive element that inserts a button. The button can be a
    trigger for anything from opening a simple link to starting a complex
    workflow.

    See: <https://api.slack.com/reference/block-kit/block-elements#button>.

    Args:
        text: text on the button (plaintext only; max 75 chars).
        action_id: an identifier so the source of the action can be known.
        url: a URL to load in the user's browser when the button is clicked.
        value: the value sent with the interaction payload.
        style: the visual style of the button, one of `primary`, `danger`.
        confirm: a `ConfirmationDialogue` object that will be presented when
            the button is clicked.
        accessibility_label: a string label for longer descriptive text about
            a button element. Used by screen readers (max 75 chars).
    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        text: TextLike,
        action_id: str,
        url: str | None = None,
        value: str | None = None,
        style: ButtonStyle | ButtonStyleName | None = None,
        confirm: ConfirmationDialogue | None = None,
        accessibility_label: str | None = None,
    ) -> None:
        super().__init__(type_=ElementType.BUTTON)
        self.text = Text.to_text(text, max_length=75, force_plaintext=True)
        self.action_id = validate_action_id(action_id)
        self.url = validate_string(url, field_name="url", max_length=3000, allow_none=True)
        self.value = validate_string(
            value,
            field_name="value",
            max_length=2000,
            allow_none=True,
        )
        self.style: str | None = None
        if isinstance(style, ButtonStyle):
            self.style = style.value
        elif isinstance(style, str):
            self.style = style
        else:
            self.style = None
        self.confirm = confirm
        self.accessibility_label = validate_string(
            accessibility_label,
            "accessibility_label",
            max_length=75,
            allow_none=True,
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "text": self.text,
                "action_id": self.action_id,
                "style": self.style,
                "url": self.url,
                "value": self.value,
                "confirm": self.confirm,
                "accessibility_label": self.accessibility_label,
            }
        )

ButtonStyle

Utility class for determining the style of Buttons and WorkflowButtons.

Source code in slackblocks/elements.py
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
class ButtonStyle(Enum):
    """
    Utility class for determining the style of `Buttons` and `WorkflowButtons`.
    """

    DEFAULT = None
    PRIMARY = "primary"
    DANGER = "danger"

    @staticmethod
    def to_button_style(style: ButtonStyle | str | None) -> ButtonStyle:
        # NOTE: this implementation uses ``ButtonStyle[style]`` which looks
        # up the enum *name* (e.g. "PRIMARY"), not the value (e.g. "primary").
        # Preserved here for backwards compatibility -- ``Button.style`` takes
        # the value form via ``ButtonStyleName``. The two paths are not
        # symmetric; see the planned Phase 7 ergonomics work for cleanup.
        if isinstance(style, ButtonStyle):
            return style
        if isinstance(style, str):
            return ButtonStyle[style]
        raise TypeMismatchError(
            f"Can only coerce to ButtonStyle from ButtonStyle or string, not {type(style)}."
        )

ChannelMultiSelectMenu

This interactive UI element allows users to select multiple channels visible to the current user in the active workspace.

See: https://api.slack.com/reference/block-kit/block-elements#channel_multi_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_channels list[str] | None

a list of conversation IDs as strings that will already be selected when the menu renders.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the menu is used.

None
max_selected_items int | None

the maximum number of items that can be selected in the menu.

None
focus_on_load bool

whether or not the menu will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the menu when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
class ChannelMultiSelectMenu(Element):
    """
    This interactive UI element allows users to select multiple channels visible
        to the current user in the active workspace.

    See: <https://api.slack.com/reference/block-kit/block-elements#channel_multi_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_channels: a list of conversation IDs as strings that will
            already be selected when the menu renders.
        confirm: a `ConfirmationDialogue` object that will be presented when
            the menu is used.
        max_selected_items: the maximum number of items that can be selected
            in the menu.
        focus_on_load: whether or not the menu will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the menu when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_channels: list[str] | None = None,
        confirm: ConfirmationDialogue | None = None,
        max_selected_items: int | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.MULTI_SELECT_CHANNELS)
        self.action_id = validate_action_id(action_id)
        self.initial_channels: list[str] | None = coerce_to_list(
            initial_channels, class_=str, allow_none=True
        )
        self.confirm = confirm
        self.max_selected_items = max_selected_items
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, force_plaintext=True, max_length=150, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_channels": self.initial_channels if self.initial_channels else None,
                "confirm": self.confirm,
                "max_selected_items": self.max_selected_items,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

ChannelSelectMenu

A select menu interactive UI element, sourced with a list of public channels visible to the current user.

See: https://api.slack.com/reference/block-kit/block-elements#channels_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_channel str | None

the single (string) user ID that will be initially selected when first presented to the user.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when an option in the overflow menu is selected.

None
response_url_enabled bool | None

When set to true, the view_submission payload from the menu's parent view will contain a response_url. (This response_url can be used for message responses).

False
focus_on_load bool

whether or not the input will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the input when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
class ChannelSelectMenu(Element):
    """
    A select menu interactive UI element, sourced with a list of public channels visible
        to the current user.

    See: <https://api.slack.com/reference/block-kit/block-elements#channels_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_channel: the single (string) user ID that will be initially selected
            when first presented to the user.
        confirm: a `ConfirmationDialogue` object that will be presented when an
            option in the overflow menu is selected.
        response_url_enabled: When set to true, the view_submission payload from the
            menu's parent view will contain a response_url. (This response_url can be
            used for message responses).
        focus_on_load: whether or not the input will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the input when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_channel: str | None = None,
        confirm: ConfirmationDialogue | None = None,
        response_url_enabled: bool | None = False,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.CHANNELS_SELECT_MENU)
        self.action_id = validate_action_id(action_id)
        self.initial_channel = initial_channel
        self.confirm = confirm
        self.response_url_enabled = response_url_enabled
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder,
            max_length=150,
            force_plaintext=True,
            allow_none=True,
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_channel": self.initial_channel if self.initial_channel else None,
                "confirm": self.confirm,
                "response_url_enabled": self.response_url_enabled
                if self.response_url_enabled
                else None,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

CheckboxGroup

A checkbox group that allows a user to choose multiple items from a list of possible options.

See: https://api.slack.com/reference/block-kit/block-elements#checkboxes.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
options Option | list[Option]

a list of Option objects that will form the content of the checkbox group.

required
initial_options Option | list[Option] | None

a list of Option objects that will be initially selected when first presented to the user.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the checkbox group is used.

None
focus_on_load bool

whether or not the checkbox group will be set to autofocus within the view object.

False
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
class CheckboxGroup(Element):
    """
    A checkbox group that allows a user to choose multiple items from a list
    of possible options.

    See: <https://api.slack.com/reference/block-kit/block-elements#checkboxes>.

    Args:
        action_id: an identifier so the source of the action can be known.
        options: a list of
            [`Option`](/slackblocks/latest/reference/objects/#objects.Option) objects that will form
            the content of the checkbox group.
        initial_options: a list of
            [`Option`](/slackblocks/latest/reference/objects/#objects.Option) objects that will be
            initially selected when first presented to the user.
        confirm: a `ConfirmationDialogue` object that will be presented when
            the checkbox group is used.
        focus_on_load: whether or not the checkbox group will be set to autofocus
            within the view object.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        options: Option | list[Option],
        initial_options: Option | list[Option] | None = None,
        confirm: ConfirmationDialogue | None = None,
        focus_on_load: bool = False,
    ) -> None:
        super().__init__(type_=ElementType.CHECKBOXES)
        self.action_id = validate_action_id(action_id)
        self.options = coerce_to_list(options, Option)
        self.initial_options = coerce_to_list(initial_options, Option, allow_none=True)
        self.confirm = confirm
        self.focus_on_load = focus_on_load

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "options": self.options,
                "initial_options": self.initial_options if self.initial_options else None,
                "confirm": self.confirm,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
            }
        )

ConversationMultiSelectMenu

This interactive UI element allows users to select multiple conversations visible to the current user in the active workspace.

See: https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_conversations list[str] | None

a list of conversation IDs as strings that will already be selected when the menu renders.

None
default_to_current_conversation bool | None

Pre-populates the select menu with the conversation that the user was viewing when they opened the modal (defaults to False).

False
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the menu is used.

None
max_selected_items int | None

the maximum number of items that can be selected in the menu.

None
filter ConversationFilter | None

a Filter object that filters out conversations that don't match the settings of the filter.

None
focus_on_load bool | None

whether or not the menu will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the menu when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
class ConversationMultiSelectMenu(Element):
    """
    This interactive UI element allows users to select multiple conversations visible
        to the current user in the active workspace.

    See: <https://api.slack.com/reference/block-kit/block-elements#conversation_multi_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_conversations: a list of conversation IDs as strings that will
            already be selected when the menu renders.
        default_to_current_conversation: Pre-populates the select menu with the
            conversation that the user was viewing when they opened the modal
            (defaults to `False`).
        confirm: a `ConfirmationDialogue` object that will be presented when
            the menu is used.
        max_selected_items: the maximum number of items that can be selected
            in the menu.
        filter: a [`Filter`](/slackblocks/latest/reference/objects/#objects.ConversationFilter)
            object that filters out conversations that don't match the settings
            of the filter.
        focus_on_load: whether or not the menu will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the menu when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_conversations: list[str] | None = None,
        default_to_current_conversation: bool | None = False,
        confirm: ConfirmationDialogue | None = None,
        max_selected_items: int | None = None,
        filter: ConversationFilter | None = None,
        focus_on_load: bool | None = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.MULTI_SELECT_CONVERSATIONS)
        self.action_id = validate_action_id(action_id)
        self.initial_conversations: list[str] | None = coerce_to_list(
            initial_conversations, str, allow_none=True
        )
        self.default_to_current_conversation = default_to_current_conversation
        self.confirm = confirm
        self.max_selected_items = max_selected_items
        self.filter = filter
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, force_plaintext=True, max_length=150, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_conversations": self.initial_conversations
                if self.initial_conversations
                else None,
                "default_to_current_conversation": self.default_to_current_conversation
                if self.default_to_current_conversation
                else None,
                "confirm": self.confirm,
                "max_selected_items": self.max_selected_items,
                "filter": self.filter,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

ConversationSelectMenu

A select menu interactive UI element, sourced with a list of public and private channels, DMs, and MPIMs visible to the current user.

See: https://api.slack.com/reference/block-kit/block-elements#conversations_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_conversation str | None

the single (string) conversation ID that will be initially selected when first presented to the user.

None
default_to_current_conversation bool | None

Pre-populates the select menu with the conversation that the user was viewing when they opened the modal (defaults to False).

False
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when an option in the overflow menu is selected.

None
response_url_enabled bool | None

When set to true, the view_submission payload from the menu's parent view will contain a response_url. (This response_url can be used for message responses).

False
filter ConversationFilter | None

a Filter object that filters out conversations that don't match the settings of the filter.

None
focus_on_load bool

whether or not the input will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the input when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
class ConversationSelectMenu(Element):
    """
    A select menu interactive UI element, sourced with a list of public and private channels,
        DMs, and MPIMs visible to the current user.

    See: <https://api.slack.com/reference/block-kit/block-elements#conversations_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_conversation: the single (string) conversation ID that will be initially
            selected when first presented to the user.
        default_to_current_conversation: Pre-populates the select menu with the
            conversation that the user was viewing when they opened the modal
            (defaults to `False`).
        confirm: a `ConfirmationDialogue` object that will be presented when an
            option in the overflow menu is selected.
        response_url_enabled: When set to true, the view_submission payload from the
            menu's parent view will contain a response_url. (This response_url can be
            used for message responses).
        filter: a [`Filter`](/slackblocks/latest/reference/objects/#objects.ConversationFilter)
            object that filters out conversations that don't match the settings
            of the filter.
        focus_on_load: whether or not the input will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the input when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_conversation: str | None = None,
        default_to_current_conversation: bool | None = False,
        confirm: ConfirmationDialogue | None = None,
        response_url_enabled: bool | None = False,
        filter: ConversationFilter | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.CONVERSATIONS_SELECT_MENU)
        self.action_id = validate_action_id(action_id)
        self.initial_conversation = initial_conversation
        self.default_to_current_conversation = default_to_current_conversation
        self.confirm = confirm
        self.response_url_enabled = response_url_enabled
        self.filter = filter
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder,
            max_length=150,
            force_plaintext=True,
            allow_none=True,
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_conversation": self.initial_conversation
                if self.initial_conversation
                else None,
                "default_to_current_conversation": self.default_to_current_conversation
                if self.default_to_current_conversation
                else None,
                "confirm": self.confirm,
                "response_url_enabled": self.response_url_enabled
                if self.response_url_enabled
                else None,
                "filter": self.filter,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

DatePicker

Interactive element that allows users to select a date from a calendar.

See: https://api.slack.com/reference/block-kit/block-elements#datepicker.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_date str | None

the date (in YYYY-MM-DD format) that will appear on the picker when it first renders.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the date picker is clicked.

None
focus_on_load bool

whether or not the date picker will be set to autofocus within the view object.

False
placeholder TextLike | None

a TextType.PLAINTEXT Text object that defines what text will initially appear on the picker.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
class DatePicker(Element):
    """
    Interactive element that allows users to select a date from a calendar.

    See: <https://api.slack.com/reference/block-kit/block-elements#datepicker>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_date: the date (in `YYYY-MM-DD` format) that will appear on the
            picker when it first renders.
        confirm: a `ConfirmationDialogue` object that will be presented when
            the date picker is clicked.
        focus_on_load: whether or not the date picker will be set to autofocus
            within the view object.
        placeholder: a `TextType.PLAINTEXT` `Text` object that defines what text
            will initially appear on the picker.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_date: str | None = None,
        confirm: ConfirmationDialogue | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.DATE_PICKER)
        self.action_id = validate_action_id(action_id)
        self.initial_date: str | None = None
        if initial_date:
            self.initial_date = datetime.strptime(initial_date, "%Y-%m-%d").strftime("%Y-%m-%d")
        self.confirm = confirm
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, force_plaintext=True, max_length=150, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_date": self.initial_date,
                "confirm": self.confirm,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

DateTimePicker

Allows users to select both a date and a time of day.

Provides the date-time formatted as a Unix timestamp.

See: https://api.slack.com/reference/block-kit/block-elements#datetimepicker.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_datetime int | None

the initial value the date-time picker will be set to when it first renders.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the button is date-time picker is used.

None
focus_on_load bool

whether or not the datetime picker will be set to autofocus within the view object.

False

Throws: InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
class DateTimePicker(Element):
    """
    Allows users to select both a date and a time of day.

    Provides the date-time formatted as a Unix timestamp.

    See: <https://api.slack.com/reference/block-kit/block-elements#datetimepicker>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_datetime: the initial value the date-time picker will be set to
            when it first renders.
        confirm: a `ConfirmationDialogue` object that will be presented when
            the button is date-time picker is used.
        focus_on_load: whether or not the datetime picker will be set to autofocus
            within the view object.
    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_datetime: int | None = None,
        confirm: ConfirmationDialogue | None = None,
        focus_on_load: bool = False,
    ) -> None:
        super().__init__(type_=ElementType.DATETIME_PICKER)
        self.action_id = validate_action_id(action_id)
        self.initial_datetime = initial_datetime
        self.confirm = confirm
        self.focus_on_load = focus_on_load

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_date_time": self.initial_datetime if self.initial_datetime else None,
                "confirm": self.confirm,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
            }
        )

EmailInput

Allows user to enter an email into a single-line text field.

See: https://api.slack.com/reference/block-kit/block-elements#email.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_value str | None

The initial value in the email input when it is loaded.

None
dispatch_action_config DispatchActionConfiguration | None

a DispatchActionConfiguration object that determines when during text input the element returns a block_actions payload.

None
focus_on_load bool

whether or not the email input will be set to autofocus within the view object.

False
placeholder TextLike | None

a TextType.PLAINTEXT Text object that defines what text will initially appear in the input field.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
class EmailInput(Element):
    """
    Allows user to enter an email into a single-line text field.

    See: <https://api.slack.com/reference/block-kit/block-elements#email>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_value: The initial value in the email input when it is loaded.
        dispatch_action_config: a `DispatchActionConfiguration` object that
            determines when during text input the element returns a
            `block_actions` payload.
        focus_on_load: whether or not the email input will be set to autofocus
            within the view object.
        placeholder: a `TextType.PLAINTEXT` `Text` object that defines what text
            will initially appear in the input field.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_value: str | None = None,
        dispatch_action_config: DispatchActionConfiguration | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.EMAIL_INPUT)
        self.action_id = validate_action_id(action_id)
        self.initial_value = initial_value
        self.dispatch_action_config = dispatch_action_config
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, max_length=150, force_plaintext=True, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_value": self.initial_value if self.initial_value else None,
                "dispatch_action_config": self.dispatch_action_config,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

ExternalMultiSelectMenu

An interactive UI element that loads its options from an external data source, allowing for a dynamic list of options.

See: https://api.slack.com/reference/block-kit/block-elements#external_multi_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
min_query_length int | None

minimum number of characters entered before the query is dispactched (defaults to 3 if not provided).

None
initial_options Option | list[Option] | OptionGroup | list[OptionGroup] | None

the Options to be initially selected when the element is first rendered.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the menu is used.

None
max_selected_items int | None

the highest number of items from the list that can be selected at one time.

None
focus_on_load bool

whether or not the menu will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the menu when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
class ExternalMultiSelectMenu(Element):
    """
    An interactive UI element that loads its options from an external data source,
        allowing for a dynamic list of options.

    See: <https://api.slack.com/reference/block-kit/block-elements#external_multi_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        min_query_length: minimum number of characters entered before the query
            is dispactched (defaults to 3 if not provided).
        initial_options: the [`Options`](/slackblocks/latest/reference/objects/#objects.Option)
            to be initially selected when the element is first rendered.
        confirm: a `ConfirmationDialogue` object that will be presented when
            the menu is used.
        max_selected_items: the highest number of items from the list that
            can be selected at one time.
        focus_on_load: whether or not the menu will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the menu when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        min_query_length: int | None = None,
        initial_options: Option | list[Option] | OptionGroup | list[OptionGroup] | None = None,
        confirm: ConfirmationDialogue | None = None,
        max_selected_items: int | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.MULTI_SELECT_EXTERNAL)
        self.action_id = validate_action_id(action_id)
        self.min_query_length = min_query_length
        self.initial_options = coerce_to_list(
            initial_options,  # type: ignore
            class_=(Option, OptionGroup),
            allow_none=True,
            max_size=100,
        )
        self.confirm = confirm
        self.max_selected_items = max_selected_items
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, force_plaintext=True, max_length=150, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "min_query_length": self.min_query_length,
                "initial_options": self.initial_options if self.initial_options else None,
                "confirm": self.confirm,
                "max_selected_items": self.max_selected_items,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

ExternalSelectMenu

A select menu interactive UI element, sourced with externally provided options.

See

https://api.slack.com/slackblocks/latest/reference/block-kit/block-elements#external_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_option Option | OptionGroup | None

an Option object that will be initially selected when first presented to the user.

None
min_query_length int | None

minimum number of characters entered before the query is dispactched (defaults to 3 if not provided).

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when an option in the overflow menu is selected.

None
focus_on_load bool

whether or not the input will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the input when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
class ExternalSelectMenu(Element):
    """
    A select menu interactive UI element, sourced with externally provided options.

    See:
        <https://api.slack.com/slackblocks/latest/reference/block-kit/block-elements#external_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_option: an
            [`Option`](/slackblocks/latest/reference/objects/#objects.Option) object that will be
            initially selected when first presented to the user.
        min_query_length: minimum number of characters entered before the query
            is dispactched (defaults to 3 if not provided).
        confirm: a `ConfirmationDialogue` object that will be presented when an
            option in the overflow menu is selected.
        focus_on_load: whether or not the input will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the input when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_option: Option | OptionGroup | None = None,
        min_query_length: int | None = None,
        confirm: ConfirmationDialogue | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.EXTERNAL_SELECT_MENU)
        self.action_id = validate_action_id(action_id)
        self.initial_option = initial_option
        self.min_query_length = min_query_length
        self.confirm = confirm
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder,
            max_length=150,
            force_plaintext=True,
            allow_none=True,
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_option": self.initial_option,
                "min_query_length": self.min_query_length,
                "confirm": self.confirm,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

FileInput

An interactive element that allows users to upload files.

See: https://api.slack.com/reference/block-kit/block-elements#file_input.

Parameters:

Name Type Description Default
action_id str | None

an identifier so the source of the action can be known.

None
filetypes str | list[str] | None

a list of file extensions (as strings) that will be accepted for upload.

None
max_files int | None

the maximum number of files that can be uploaded (between 1 and 10).

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
class FileInput(Element):
    """
    An interactive element that allows users to upload files.

    See: <https://api.slack.com/reference/block-kit/block-elements#file_input>.

    Args:
        action_id: an identifier so the source of the action can be known.
        filetypes: a list of file extensions (as strings) that will be accepted
            for upload.
        max_files: the maximum number of files that can be uploaded (between 1
            and 10).

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str | None = None,
        filetypes: str | list[str] | None = None,
        max_files: int | None = None,
    ) -> None:
        super().__init__(ElementType.FILE_INPUT)
        self.action_id = validate_action_id(action_id)
        self.filetypes = coerce_to_list(
            filetypes,
            (str),
            allow_none=True,
        )
        self.max_files = validate_int(max_files, min_value=1, max_value=10, allow_none=True)

    def _resolve(self) -> dict[str, Any]:
        # FileInput currently does not emit the "type" attribute; this is
        # preserved from prior behaviour. The pre-existing #154 export work
        # surfaced this class but did not change its rendering contract.
        return resolve(
            {
                "action_id": self.action_id,
                "filetypes": self.filetypes,
                "max_files": self.max_files,
            }
        )

Image

An element to insert an image - this element can be used in section and context blocks only. If you want a block with only an image in it, you're looking for the Image block.

You must provide either one of image_url or slack_file

See: https://api.slack.com/reference/block-kit/block-elements#image.

Parameters:

Name Type Description Default
alt_text str

a plain-text-only summary of the content of the image.

' '
image_url str | None

a URL for a publicly hosted image (the user must provide either image_url or slack_file).

None
slack_file SlackFile | None

a SlackFile (the user must provide either image_url or slack_file).

None
Throws

InvalidUsageError: if any of the provided arguments fail validation, or both/neither of image_url and slack_file are provided.

Source code in slackblocks/elements.py
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
class Image(Element):
    """
    An element to insert an image - this element can be used in section
    and context blocks only. If you want a block with only an image in it,
    you're looking for the Image block.

    You must provide either one of `image_url` or `slack_file`

    See: <https://api.slack.com/reference/block-kit/block-elements#image>.

    Args:
        alt_text: a plain-text-only summary of the content of the image.
        image_url: a URL for a publicly hosted image (the user must provide
            either `image_url` or `slack_file`).
        slack_file: a [`SlackFile`](/slackblocks/latest/reference/objects/#objects.SlackFile)
            (the user must provide either `image_url` or `slack_file`).

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation,
            or both/neither of `image_url` and `slack_file` are provided.
    """

    def __init__(
        self,
        alt_text: str = " ",
        image_url: str | None = None,
        slack_file: SlackFile | None = None,
    ) -> None:
        super().__init__(type_=ElementType.IMAGE)
        if image_url is None and slack_file is None:
            raise MissingRequiredError("Must provide one of `image_url` or `slack_file`")
        if image_url and slack_file:
            raise MutualExclusivityError("Cannot provide both `image_url` or `slack_file`")
        self.image_url = image_url
        self.alt_text = alt_text
        self.slack_file = slack_file

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "image_url": self.image_url,
                "alt_text": self.alt_text,
                "slack_file": self.slack_file,
            }
        )

NumberInput

This input elements accepts both integer and decimal numbers. For example, 0.25, 5.5, and -10 are all valid input values.

See https://api.slack.com/reference/block-kit/block-elements#number.

Parameters:

Name Type Description Default
is_decimal_allowed bool

whether to accept decimal values as input.

required
action_id str | None

an identifier so the source of the action can be known.

None
initial_value str | None

the initial value in the number input when it is loaded.

None
min_value float | int | None

minimum accepted value for the input field.

None
max_value float | int | None

maximum accepted value for the input field.

None
dispatch_action_config DispatchActionConfiguration | None

a DispatchActionConfiguration object that determines when during text input the element returns a block_actions payload.

None
focus_on_load bool

whether or not the menu will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the input when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
class NumberInput(Element):
    """
    This input elements accepts both integer and decimal numbers. For example,
    0.25, 5.5, and -10 are all valid input values.

    See <https://api.slack.com/reference/block-kit/block-elements#number>.

    Args:
        is_decimal_allowed: whether to accept decimal values as input.
        action_id: an identifier so the source of the action can be known.
        initial_value: the initial value in the number input when it is loaded.
        min_value: minimum accepted value for the input field.
        max_value: maximum accepted value for the input field.
        dispatch_action_config: a `DispatchActionConfiguration` object that
            determines when during text input the element returns a
            `block_actions` payload.
        focus_on_load: whether or not the menu will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the input when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        is_decimal_allowed: bool,
        action_id: str | None = None,
        initial_value: str | None = None,
        min_value: float | int | None = None,
        max_value: float | int | None = None,
        dispatch_action_config: DispatchActionConfiguration | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.NUMBER_INPUT)
        self.is_decimal_allowed = is_decimal_allowed
        self.action_id = validate_action_id(action_id, allow_none=True)
        self.initial_value = initial_value
        self.min_value = min_value
        self.max_value = max_value
        if min_value and not is_decimal_allowed and isinstance(min_value, float):
            raise TypeMismatchError(
                f"`min_value` ({min_value}) cannot be a float when `is_decimal_allowed` is `False`"
            )
        if max_value and not is_decimal_allowed and isinstance(max_value, float):
            raise TypeMismatchError(
                f"`max_value` ({max_value}) cannot be a float when `is_decimal_allowed` is `False`"
            )
        if min_value is not None and max_value is not None and min_value > max_value:
            raise RangeError(
                f"`min_value` ({min_value}) cannot be greater than `max_value` ({max_value})"
            )
        self.dispatch_action_config = dispatch_action_config
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, max_length=150, force_plaintext=True, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "is_decimal_allowed": self.is_decimal_allowed,
                "action_id": self.action_id if self.action_id else None,
                "initial_value": self.initial_value if self.initial_value else None,
                "min_value": self.min_value,
                "max_value": self.max_value,
                "dispatch_action_config": self.dispatch_action_config,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

OverflowMenu

Context menu for additional options (think '...').

See https://api.slack.com/reference/block-kit/block-elements#overflow.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
options Option | list[Option]

a list of Option objects that will form the content of the overflow menu.

required
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when an option in the overflow menu is selected.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
class OverflowMenu(Element):
    """
    Context menu for additional options (think '...').

    See <https://api.slack.com/reference/block-kit/block-elements#overflow>.

    Args:
        action_id: an identifier so the source of the action can be known.
        options: a list of
            [`Option`](/slackblocks/latest/reference/objects/#objects.Option) objects that will form
            the content of the overflow menu.
        confirm: a `ConfirmationDialogue` object that will be presented when an
            option in the overflow menu is selected.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        options: Option | list[Option],
        confirm: ConfirmationDialogue | None = None,
    ) -> None:
        super().__init__(type_=ElementType.OVERFLOW_MENU)
        self.action_id = validate_action_id(action_id)
        self.options = coerce_to_list(options, Option, min_size=1, max_size=5)
        self.confirm = confirm

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "options": [option for option in self.options if option is not None]
                if self.options is not None
                else None,
                "confirm": self.confirm,
            }
        )

PlainTextInput

A plain-text input, similar to the HTML tag, creates a field where a user can enter freeform data. It can appear as a single-line field or a larger text area using the multiline flag.

See: https://api.slack.com/reference/block-kit/block-elements#input.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_value str | None

the initial value in the plain-text input when it is loaded.

None
multiline bool

whether to accept multiple lines of input(defaults to false).

False
min_length int | None

minimum number of characters to accept as input.

None
max_length int | None

maximum number of characters to accept as input.

None
dispatch_action_config DispatchActionConfiguration | None

a DispatchActionConfiguration object that determines when during text input the element returns a block_actions payload.

None
focus_on_load bool

whether or not the input will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the input when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
class PlainTextInput(Element):
    """
    A plain-text input, similar to the HTML <input> tag, creates a field where a user
    can enter freeform data. It can appear as a single-line field or a larger text
    area using the multiline flag.

    See: <https://api.slack.com/reference/block-kit/block-elements#input>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_value: the initial value in the plain-text input when it is loaded.
        multiline: whether to accept multiple lines of input(defaults to false).
        min_length: minimum number of characters to accept as input.
        max_length: maximum number of characters to accept as input.
        dispatch_action_config: a `DispatchActionConfiguration` object that
            determines when during text input the element returns a
            `block_actions` payload.
        focus_on_load: whether or not the input will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the input when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_value: str | None = None,
        multiline: bool = False,
        min_length: int | None = None,
        max_length: int | None = None,
        dispatch_action_config: DispatchActionConfiguration | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.PLAIN_TEXT_INPUT)
        self.action_id = validate_action_id(action_id)
        self.multiline = multiline
        self.initial_value = initial_value
        self.min_length = min_length
        if max_length and max_length > 3000:
            raise RangeError("`max_length` value cannot exceed 3000 characters")
        self.max_length = max_length
        self.dispatch_action_config = dispatch_action_config
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, max_length=150, force_plaintext=True, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "multiline": self.multiline if self.multiline else None,
                "action_id": self.action_id if self.action_id else None,
                "initial_value": self.initial_value if self.initial_value else None,
                "min_length": self.min_length if self.min_length else None,
                "max_length": self.max_length if self.max_length else None,
                "dispatch_action_config": self.dispatch_action_config,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

RadioButtonGroup

A radio button group that allows a user to choose one item from a list of possible options.

See: https://api.slack.com/reference/block-kit/block-elements#radio.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
options list[Option]

a list of Option objects that will form the content of the radio button group.

required
initial_option Option | None

an Option object that will be initially selected when first presented to the user.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when an option in the overflow menu is selected.

None
focus_on_load bool

whether or not the input will be set to autofocus within the view object.

False
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
class RadioButtonGroup(Element):
    """
    A radio button group that allows a user to choose one item from a list of possible options.

    See: <https://api.slack.com/reference/block-kit/block-elements#radio>.

    Args:
        action_id: an identifier so the source of the action can be known.
        options: a list of
            [`Option`](/slackblocks/latest/reference/objects/#objects.Option) objects that will form
            the content of the radio button group.
        initial_option: an
            [`Option`](/slackblocks/latest/reference/objects/#objects.Option) object that will be
            initially selected when first presented to the user.
        confirm: a `ConfirmationDialogue` object that will be presented when an
            option in the overflow menu is selected.
        focus_on_load: whether or not the input will be set to autofocus
            within the view object.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        options: list[Option],
        initial_option: Option | None = None,
        confirm: ConfirmationDialogue | None = None,
        focus_on_load: bool = False,
    ) -> None:
        super().__init__(type_=ElementType.RADIO_BUTTON_GROUP)
        self.action_id = validate_action_id(action_id)
        if len(options) < 1 or len(options) > 10:
            raise LengthError(
                "Number of options to RadioButtonGroup must be between 1 and 10 (inclusive)."
            )
        self.options: list[Option] | None = coerce_to_list(options, class_=Option, allow_none=False)
        if initial_option is not None and initial_option not in options:
            raise TypeMismatchError("`initial_option` must be a member of `options`")
        self.initial_option = initial_option
        self.confirm = confirm
        self.focus_on_load = focus_on_load

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "options": self.options,
                "initial_option": self.initial_option,
                "confirm": self.confirm,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
            }
        )

RichTextInput

Allows users to enter formatted text in a WYSIWYG editor, similar to the Slack messaging experience.

See: https://api.slack.com/reference/block-kit/block-elements#rich_text_input.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_value RichText | None

The initial value in the rich text input when it is loaded.

None
dispatch_action_config DispatchActionConfiguration | None

a DispatchActionConfiguration object that determines when during text input the element returns a block_actions payload.

None
focus_on_load bool

whether or not the menu will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the menu when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
class RichTextInput(Element):
    """
    Allows users to enter formatted text in a WYSIWYG editor, similar to the Slack
        messaging experience.

    See: <https://api.slack.com/reference/block-kit/block-elements#rich_text_input>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_value: The initial value in the rich text input when it is loaded.
        dispatch_action_config: a `DispatchActionConfiguration` object that
            determines when during text input the element returns a
            `block_actions` payload.
        focus_on_load: whether or not the menu will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the menu when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_value: RichText | None = None,
        dispatch_action_config: DispatchActionConfiguration | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(ElementType.RICH_TEXT_INPUT)
        self.action_id = validate_action_id(action_id)
        self.initial_value = initial_value
        self.dispatch_action_config = dispatch_action_config
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder,
            force_plaintext=True,
            max_length=150,
            allow_none=True,
        )

    def _resolve(self) -> dict[str, Any]:
        # Note: focus_on_load is emitted unconditionally (the check used to be
        # ``if self.focus_on_load is not None``, which is always true given the
        # default of False). Preserving this behaviour to avoid breaking the
        # existing test golden file.
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_value": self.initial_value,
                "dispatch_action_config": self.dispatch_action_config,
                "focus_on_load": self.focus_on_load,
                "placeholder": self.placeholder,
            }
        )

StaticMultiSelectMenu

The most basic form of select menu containing a static list of options passed in when defining the element.

See: https://api.slack.com/reference/block-kit/block-elements#static_multi_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
options Option | list[Option]

a list of Options (max 100). Only one of options or option_groups must be provided.

required
option_groups OptionGroup | list[OptionGroup] | None

a list of OptionGroups (max 100). Only one of options or option_groups can be provided.

None
initial_options Option | list[Option] | OptionGroup | list[OptionGroup] | None

the Options to be initially selected when the element is first rendered.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the menu is used.

None
max_selected_items int | None

the

None
focus_on_load bool

whether or not the menu will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the menu when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
class StaticMultiSelectMenu(Element):
    """
    The most basic form of select menu containing a static list of options
    passed in when defining the element.

    See: <https://api.slack.com/reference/block-kit/block-elements#static_multi_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        options: a list of [`Options`](/slackblocks/latest/reference/objects/#objects.Option)
            (max 100). Only one of `options` or `option_groups` must be
            provided.
        option_groups: a list of
            [`OptionGroups`](/slackblocks/latest/reference/objects/#objects.OptionGroup)
            (max 100). Only one of `options` or `option_groups` can be
            provided.
        initial_options: the [`Options`](/slackblocks/latest/reference/objects/#objects.Option)
            to be initially selected when the element is first rendered.
        confirm: a `ConfirmationDialogue` object that will be presented when
            the menu is used.
        max_selected_items: the
        focus_on_load: whether or not the menu will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the menu when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        options: Option | list[Option],
        option_groups: OptionGroup | list[OptionGroup] | None = None,
        initial_options: Option | list[Option] | OptionGroup | list[OptionGroup] | None = None,
        confirm: ConfirmationDialogue | None = None,
        max_selected_items: int | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.MULTI_SELECT_STATIC)
        self.action_id = validate_action_id(action_id)
        if options and option_groups:
            raise MutualExclusivityError(
                "Cannot set both `options` and `option_groups` parameters."
            )
        self.options = coerce_to_list(options, class_=Option, allow_none=True, max_size=100)
        self.option_groups = coerce_to_list(
            option_groups, class_=OptionGroup, allow_none=True, max_size=100
        )
        self.initial_options = coerce_to_list(
            initial_options,  # type: ignore
            class_=(Option, OptionGroup),
            allow_none=True,
            max_size=100,
        )
        if (
            options
            and self.initial_options
            and not all(isinstance(option, Option) for option in self.initial_options)
        ):
            raise TypeMismatchError(
                "If using `options` then `initial_options` must also be of type `List[Option]`, "
                f"not `{type(self.initial_options)}`."
            )
        if (
            option_groups
            and self.initial_options
            and not all(isinstance(option, OptionGroup) for option in self.initial_options)
        ):
            raise TypeMismatchError(
                "If using `option_groups` then `initial_options` must also be of type "
                f"`List[OptionGroup]`, not `{type(self.initial_options)}`."
            )

        # Check that Option Text is all TextType.PLAINTEXT
        options_to_validate: list[Option] = []
        if self.options:
            options_to_validate = self.options
        if self.option_groups:
            options_to_validate = list(
                chain.from_iterable(option_group.options for option_group in self.option_groups)
            )
        for option in options_to_validate:
            if option.text.text_type == TextType.MARKDOWN:
                raise TypeMismatchError(
                    "Text in Options for StaticSelectMenu can only be of TextType.PLAINTEXT"
                )

        self.confirm = confirm
        self.max_selected_items = max_selected_items
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, force_plaintext=True, max_length=150, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "options": self.options if self.options else None,
                "option_groups": self.option_groups if self.option_groups else None,
                "initial_options": self.initial_options if self.initial_options else None,
                "confirm": self.confirm,
                "max_selected_items": self.max_selected_items,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

StaticSelectMenu

A simple select menu interactive UI element, with a static list of options passed in when defining the element.

See: https://api.slack.com/reference/block-kit/block-elements#static_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
options list[Option] | None

a list of Option objects that will form the content of the menu (max 100).

None
option_groups list[OptionGroup] | None

a list of OptionGroups (max 100). Only one of options or option_groups can be provided.

None
initial_option Option | OptionGroup | None

an Option object that will be initially selected when first presented to the user.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when an option in the overflow menu is selected.

None
focus_on_load bool

whether or not the input will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the input when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
class StaticSelectMenu(Element):
    """
    A simple select menu interactive UI element, with a static list of options passed in when
        defining the element.

    See: <https://api.slack.com/reference/block-kit/block-elements#static_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        options: a list of
            [`Option`](/slackblocks/latest/reference/objects/#objects.Option) objects that will form
            the content of the menu (max 100).
        option_groups: a list of
            [`OptionGroups`](/slackblocks/latest/reference/objects/#objects.OptionGroup)
            (max 100). Only one of `options` or `option_groups` can be
            provided.
        initial_option: an
            [`Option`](/slackblocks/latest/reference/objects/#objects.Option) object that will be
            initially selected when first presented to the user.
        confirm: a `ConfirmationDialogue` object that will be presented when an
            option in the overflow menu is selected.
        focus_on_load: whether or not the input will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the input when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        options: list[Option] | None = None,
        option_groups: list[OptionGroup] | None = None,
        initial_option: Option | OptionGroup | None = None,
        confirm: ConfirmationDialogue | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.STATIC_SELECT_MENU)
        self.action_id = validate_action_id(action_id)
        if options and option_groups:
            raise MutualExclusivityError(
                "Cannot set both `options` and `option_groups` parameters."
            )
        self.options: list[Option] | None = coerce_to_list(
            options, class_=Option, allow_none=True, max_size=100
        )
        self.option_groups: list[OptionGroup] | None = coerce_to_list(
            option_groups, class_=OptionGroup, allow_none=True, max_size=100
        )
        if options and initial_option and not isinstance(initial_option, Option):
            raise TypeMismatchError(
                "If using `options` then `initial_option` must also be of type `Option`, "
                f"not `{type(initial_option)}`."
            )
        if option_groups and initial_option and not isinstance(initial_option, OptionGroup):
            raise TypeMismatchError(
                "If using `option_groups` then `initial_option` must also be of type "
                f"`OptionGroup`, not `{type(initial_option)}`."
            )

        # Check that Option Text is all TextType.PLAINTEXT
        options_to_validate: list[Option] = []
        if self.options:
            options_to_validate = self.options
        if self.option_groups:
            options_to_validate = list(
                chain.from_iterable(option_group.options for option_group in self.option_groups)
            )
        for option in options_to_validate:
            if option.text.text_type == TextType.MARKDOWN:
                raise TypeMismatchError(
                    "Text in Options for StaticSelectMenu can only be of TextType.PLAINTEXT"
                )

        self.initial_option = initial_option
        self.confirm = confirm
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, max_length=150, force_plaintext=True, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "options": self.options if self.options else None,
                "option_groups": self.option_groups if self.option_groups else None,
                "initial_option": self.initial_option,
                "confirm": self.confirm,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

TimePicker

An interactive UI element that allows users to select a time of day.

See: https://api.slack.com/reference/block-kit/block-elements#timepicker.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_time str | None
None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the input field is used.

None
focus_on_load bool

whether or not the menu will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the menu when it's initially rendered.

None
timezone str | None

a string in the IANA format, e.g. "America/Chicago".

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
class TimePicker(Element):
    """
    An interactive UI element that allows users to select a time of day.

    See: <https://api.slack.com/reference/block-kit/block-elements#timepicker>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_time:
        confirm: a `ConfirmationDialogue` object that will be presented when
            the input field is used.
        focus_on_load: whether or not the menu will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the menu when it's initially rendered.
        timezone: a string in the IANA format, e.g. "America/Chicago".

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_time: str | None = None,
        confirm: ConfirmationDialogue | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
        timezone: str | None = None,
    ) -> None:
        super().__init__(type_=ElementType.TIME_PICKER)
        self.action_id = validate_action_id(action_id)
        self.initial_time = initial_time
        self.confirm = confirm
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder,
            max_length=150,
            force_plaintext=True,
            allow_none=True,
        )
        self.timezone = timezone

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_time": self.initial_time if self.initial_time else None,
                "confirm": self.confirm,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
                "timezone": self.timezone,
            }
        )

URLInput

An interactive UI element for collecting URL input from users.

See: https://api.slack.com/reference/block-kit/block-elements#url.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_value str | None

the text to populate the input field with when it is first rendered.

None
dispatch_action_config DispatchActionConfiguration | None

a DispatchActionConfiguration object that determines when during text input the element returns a block_actions payload.

None
focus_on_load bool

whether or not the menu will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the input when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
class URLInput(Element):
    """
    An interactive UI element for collecting URL input from users.

    See: <https://api.slack.com/reference/block-kit/block-elements#url>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_value: the text to populate the input field with when it
            is first rendered.
        dispatch_action_config: a `DispatchActionConfiguration` object that
            determines when during text input the element returns a
            `block_actions` payload.
        focus_on_load: whether or not the menu will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the input when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_value: str | None = None,
        dispatch_action_config: DispatchActionConfiguration | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.URL_INPUT)
        self.action_id = validate_action_id(action_id)
        self.initial_value = initial_value
        self.dispatch_action_config = dispatch_action_config
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder,
            force_plaintext=True,
            max_length=150,
            allow_none=True,
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_value": self.initial_value,
                "dispatch_action_config": self.dispatch_action_config,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

UserMultiSelectMenu

This interactive UI element allows users to select multiple users visible to the current user in the active workspace.

See: https://api.slack.com/reference/block-kit/block-elements#users_multi_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_users list[str] | None

a list of string user IDs to be initially selected when the element is first rendered.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when the menu is used.

None
max_selected_items int | None

the highest number of items from the list that can be selected at one time.

None
focus_on_load bool

whether or not the menu will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the menu when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
class UserMultiSelectMenu(Element):
    """
    This interactive UI element allows users to select multiple users visible
        to the current user in the active workspace.

    See: <https://api.slack.com/reference/block-kit/block-elements#users_multi_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_users: a list of string user IDs to be initially selected
            when the element is first rendered.
        confirm: a `ConfirmationDialogue` object that will be presented when
            the menu is used.
        max_selected_items: the highest number of items from the list that
            can be selected at one time.
        focus_on_load: whether or not the menu will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the menu when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_users: list[str] | None = None,
        confirm: ConfirmationDialogue | None = None,
        max_selected_items: int | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.MULTI_SELECT_USERS)
        self.action_id = validate_action_id(action_id)
        self.initial_users: list[str] | None = coerce_to_list(initial_users, str, allow_none=True)
        self.confirm = confirm
        self.max_selected_items = max_selected_items
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, force_plaintext=True, max_length=150, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_users": self.initial_users if self.initial_users else None,
                "confirm": self.confirm,
                "max_selected_items": self.max_selected_items,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

UserSelectMenu

A select menu interactive UI element, sourced automatically with Slack users from the current workspace visible to the current user.

See: https://api.slack.com/reference/block-kit/block-elements#users_select.

Parameters:

Name Type Description Default
action_id str

an identifier so the source of the action can be known.

required
initial_user str | None

the single (string) user ID that will be initially selected when first presented to the user.

None
confirm ConfirmationDialogue | None

a ConfirmationDialogue object that will be presented when an option in the overflow menu is selected.

None
focus_on_load bool

whether or not the input will be set to autofocus within the view object.

False
placeholder TextLike | None

a plain-text Text object (max 150 chars) that shows in the input when it's initially rendered.

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
class UserSelectMenu(Element):
    """
    A select menu interactive UI element, sourced automatically with Slack users from the
        current workspace visible to the current user.

    See: <https://api.slack.com/reference/block-kit/block-elements#users_select>.

    Args:
        action_id: an identifier so the source of the action can be known.
        initial_user: the single (string) user ID that will be initially selected
            when first presented to the user.
        confirm: a `ConfirmationDialogue` object that will be presented when an
            option in the overflow menu is selected.
        focus_on_load: whether or not the input will be set to autofocus
            within the view object.
        placeholder: a plain-text `Text` object (max 150 chars) that shows
            in the input when it's initially rendered.

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        action_id: str,
        initial_user: str | None = None,
        confirm: ConfirmationDialogue | None = None,
        focus_on_load: bool = False,
        placeholder: TextLike | None = None,
    ) -> None:
        super().__init__(type_=ElementType.USERS_SELECT_MENU)
        self.action_id = validate_action_id(action_id)
        self.initial_user = initial_user
        self.confirm = confirm
        self.focus_on_load = focus_on_load
        self.placeholder = Text.to_text(
            placeholder, max_length=150, force_plaintext=True, allow_none=True
        )

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "action_id": self.action_id,
                "initial_user": self.initial_user if self.initial_user else None,
                "confirm": self.confirm,
                "focus_on_load": self.focus_on_load if self.focus_on_load else None,
                "placeholder": self.placeholder if self.placeholder else None,
            }
        )

WorkflowButton

An interactive component that allows users to run a link trigger with customizable inputs.

See: https://api.slack.com/reference/block-kit/block-elements#workflow_button.

Parameters:

Name Type Description Default
text TextLike

the text content that will appear in the button.

required
workflow Workflow | None

a Workflow object that contains details about the workflow that will run when the button is clicked.

None
style ButtonStyleLike | None

one of Default, Primary, or Danger, determines the visual style of the button. Consider using the ButtonStyle object for this.

DEFAULT
accessibility_label str | None

a string label for longer descriptive text about a button element. Used by screen readers (max 75 chars).

None
Throws

InvalidUsageError: if any of the provided arguments fail validation.

Source code in slackblocks/elements.py
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
class WorkflowButton(Element):
    """
    An interactive component that allows users to run a link trigger with
        customizable inputs.

    See: <https://api.slack.com/reference/block-kit/block-elements#workflow_button>.

    Args:
        text: the text content that will appear in the button.
        workflow: a [`Workflow`](/slackblocks/latest/reference/objects/#objects.Workflow) object
            that contains details about the workflow that will run when the
            button is clicked.
        style: one of `Default`, `Primary`, or `Danger`, determines the
            visual style of the button. Consider using the `ButtonStyle`
            object for this.
        accessibility_label: a string label for longer descriptive text about
            a button element. Used by screen readers (max 75 chars).

    Throws:
        InvalidUsageError: if any of the provided arguments fail validation.
    """

    def __init__(
        self,
        text: TextLike,
        workflow: Workflow | None = None,
        style: ButtonStyleLike | None = ButtonStyle.DEFAULT,
        accessibility_label: str | None = None,
    ) -> None:
        super().__init__(type_=ElementType.WORKFLOW_BUTTON)
        self.text = Text.to_text(text, force_plaintext=True, max_length=75)
        self.workflow = workflow
        self.style = ButtonStyle.to_button_style(style).value
        self.accessibility_label = accessibility_label

    def _resolve(self) -> dict[str, Any]:
        return resolve(
            {
                **self._attributes(),
                "text": self.text,
                "workflow": self.workflow,
                "style": self.style,
                "accessibility_label": self.accessibility_label
                if self.accessibility_label
                else None,
            }
        )