Skip to content

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

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 Optional[str]

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

None
value Optional[str]

the value sent with the interaction payload.

None
style Optional[str]

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

None
confirm Optional[ConfirmationDialogue]

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

None
accessibility_label Optional[str]

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
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
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
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: Optional[str] = None,
        value: Optional[str] = None,
        style: Optional[str] = None,
        confirm: Optional[ConfirmationDialogue] = None,
        accessibility_label: Optional[str] = None,
    ) -> "Button":
        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 = style.value if isinstance(style, ButtonStyle) else style
        self.confirm = confirm
        self.accessibility_label = validate_string(
            accessibility_label,
            "accessibility_label",
            max_length=75,
            allow_none=True,
        )

    def _resolve(self) -> Dict[str, Any]:
        button = self._attributes()
        button["text"] = self.text._resolve()
        button["action_id"] = self.action_id
        if self.style:
            button["style"] = self.style
        if self.url:
            button["url"] = self.url
        if self.value:
            button["value"] = self.value
        if self.confirm:
            button["confirm"] = self.confirm._resolve()
        if self.accessibility_label:
            button["accessibility_label"] = self.accessibility_label
        return button

ButtonStyle

Utility class for determining the style of Buttons and WorkflowButtons.

Source code in slackblocks/elements.py
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
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: Optional[Union["ButtonStyle", str]]) -> "ButtonStyle":
        if isinstance(style, ButtonStyle):
            return style
        if isinstance(style, (str, None)):
            return ButtonStyle[style]
        raise InvalidUsageError(
            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 Optional[List[str]]

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

None
confirm ConfirmationDialogue

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

None
max_selected_items Optional[int]

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 Optional[TextLike]

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
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
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
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: Optional[List[str]] = None,
        confirm: ConfirmationDialogue = None,
        max_selected_items: Optional[int] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = None,
    ):
        super().__init__(type_=ElementType.MULTI_SELECT_CHANNELS)
        self.action_id = validate_action_id(action_id)
        self.initial_channels = 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]:
        channel_multi_select = self._attributes()
        channel_multi_select["action_id"] = self.action_id
        if self.initial_channels:
            channel_multi_select["initial_channels"] = [
                initial_option._resolve() for initial_option in self.initial_channels
            ]
        if self.confirm:
            channel_multi_select["confirm"] = self.confirm._resolve()
        if self.max_selected_items:
            channel_multi_select["max_selected_items"] = self.max_selected_items
        if self.focus_on_load:
            channel_multi_select["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            channel_multi_select["placeholder"] = self.placeholder._resolve()
        return channel_multi_select

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 Optional[str]

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

None
confirm Optional[ConfirmationDialogue]

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

None
response_url_enabled Optional[bool]

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 Optional[TextLike]

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
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
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
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: Optional[str] = None,
        confirm: Optional[ConfirmationDialogue] = None,
        response_url_enabled: Optional[bool] = False,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = 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]:
        channel_select_menu = self._attributes()
        channel_select_menu["action_id"] = self.action_id
        if self.initial_channel:
            channel_select_menu["initial_channel"] = self.initial_channel
        if self.confirm:
            channel_select_menu["confirm"] = self.confirm._resolve()
        if self.response_url_enabled:
            channel_select_menu["response_url_enabled"] = self.response_url_enabled
        if self.focus_on_load:
            channel_select_menu["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            channel_select_menu["placeholder"] = self.placeholder._resolve()
        return channel_select_menu

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 Union[Option, List[Option]]

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

required
initial_options Optional[Union[Option, List[Option]]]

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

None
confirm ConfirmationDialogue

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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
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
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`](/reference/objects/#objects.Option) objects that will form
            the content of the checkbox group.
        initial_options: a list of
            [`Option`](/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: Union[Option, List[Option]],
        initial_options: Optional[Union[Option, List[Option]]] = None,
        confirm: ConfirmationDialogue = None,
        focus_on_load: bool = False,
    ) -> "CheckboxGroup":
        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]:
        checkbox_group = self._attributes()
        checkbox_group["action_id"] = self.action_id
        checkbox_group["options"] = [option._resolve() for option in self.options]
        if self.initial_options:
            checkbox_group["initial_options"] = [
                option._resolve() for option in self.initial_options
            ]
        if self.confirm:
            checkbox_group["confirm"] = self.confirm._resolve()
        if self.focus_on_load:
            checkbox_group["focus_on_load"] = self.focus_on_load
        return checkbox_group

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 Optional[List[str]]

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

None
default_to_current_conversation Optional[bool]

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

False
confirm ConfirmationDialogue

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

None
max_selected_items Optional[int]

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

None
filter Optional[ConversationFilter]

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

None
focus_on_load Optional[bool]

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

False
placeholder Optional[TextLike]

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
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
777
778
779
780
781
782
783
784
785
786
787
788
789
790
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`](/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: Optional[List[str]] = None,
        default_to_current_conversation: Optional[bool] = False,
        confirm: ConfirmationDialogue = None,
        max_selected_items: Optional[int] = None,
        filter: Optional[ConversationFilter] = None,
        focus_on_load: Optional[bool] = False,
        placeholder: Optional[TextLike] = None,
    ):
        super().__init__(type_=ElementType.MULTI_SELECT_CONVERSATIONS)
        self.action_id = validate_action_id(action_id)
        self.initial_conversations = 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]:
        conversation_multi_select = self._attributes()
        conversation_multi_select["action_id"] = self.action_id
        if self.initial_conversations:
            conversation_multi_select["intial_conversations"] = (
                self.initial_conversations
            )
        if self.default_to_current_conversation:
            conversation_multi_select["default_to_current_conversation"] = (
                self.default_to_current_conversation
            )
        if self.confirm:
            conversation_multi_select["confirm"] = self.confirm._resolve()
        if self.max_selected_items:
            conversation_multi_select["max_selected_items"] = self.max_selected_items
        if self.filter:
            conversation_multi_select["filter"] = self.filter._resolve()
        if self.focus_on_load:
            conversation_multi_select["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            conversation_multi_select["placeholder"] = self.placeholder._resolve()
        return conversation_multi_select

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 Optional[str]

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

None
default_to_current_conversation Optional[bool]

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

False
confirm Optional[ConfirmationDialogue]

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

None
response_url_enabled Optional[bool]

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 Optional[ConversationFilter]

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 Optional[TextLike]

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
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
1369
1370
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
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) coversation 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`](/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: Optional[str] = None,
        default_to_current_conversation: Optional[bool] = False,
        confirm: Optional[ConfirmationDialogue] = None,
        response_url_enabled: Optional[bool] = False,
        filter: Optional[ConversationFilter] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = 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]:
        conversation_select_menu = self._attributes()
        conversation_select_menu["action_id"] = self.action_id
        if self.initial_conversation:
            conversation_select_menu["initial_conversation"] = self.initial_conversation
        if self.default_to_current_conversation:
            conversation_select_menu["default_to_current_conversation"] = (
                self.default_to_current_conversation
            )
        if self.confirm:
            conversation_select_menu["confirm"] = self.confirm._resolve()
        if self.response_url_enabled:
            conversation_select_menu["response_url_enabled"] = self.response_url_enabled
        if self.filter:
            conversation_select_menu["filter"] = self.filter
        if self.focus_on_load:
            conversation_select_menu["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            conversation_select_menu["placeholder"] = self.placeholder._resolve()
        return conversation_select_menu

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 Optional[str]

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

None
confirm ConfirmationDialogue

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 Optional[TextLike]

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
212
213
214
215
216
217
218
219
220
221
222
223
224
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
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: Optional[str] = None,
        confirm: ConfirmationDialogue = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = None,
    ) -> "DatePicker":
        super().__init__(type_=ElementType.DATE_PICKER)
        self.action_id = validate_action_id(action_id)
        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]:
        date_picker = self._attributes()
        date_picker["action_id"] = self.action_id
        if self.initial_date is not None:
            date_picker["initial_date"] = self.initial_date
        if self.confirm:
            date_picker["confirm"] = self.confirm
        if self.focus_on_load:
            date_picker["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            date_picker["placeholder"] = self.placeholder._resolve()
        return date_picker

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 Optional[int]

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

None
confirm ConfirmationDialogue

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
267
268
269
270
271
272
273
274
275
276
277
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
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: Optional[int] = None,
        confirm: ConfirmationDialogue = None,
        focus_on_load: bool = False,
    ) -> "DateTimePicker":
        super().__init__(type_=ElementType.DATETIME_PICKER)
        self.action_id = validate_action_id(action_id)
        if initial_datetime:
            self.initial_datetime = initial_datetime
        self.confirm = confirm
        self.focus_on_load = focus_on_load

    def _resolve(self) -> Dict[str, Any]:
        datetime_picker = self._attributes()
        datetime_picker["action_id"] = self.action_id
        if self.initial_datetime:
            datetime_picker["initial_date_time"] = self.initial_datetime
        if self.confirm:
            datetime_picker["confirm"] = self.confirm
        if self.focus_on_load:
            datetime_picker["focus_on_load"] = self.focus_on_load
        return datetime_picker

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 Optional[str]

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

None
dispatch_action_config Optional[DispatchActionConfiguration]

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 Optional[TextLike]

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
313
314
315
316
317
318
319
320
321
322
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
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: Optional[str] = None,
        dispatch_action_config: Optional[DispatchActionConfiguration] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = 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):
        email_input = self._attributes()
        email_input["action_id"] = self.action_id
        if self.initial_value:
            email_input["initial_value"] = self.initial_value
        if self.dispatch_action_config:
            email_input["dispatch_action_config"] = (
                self.dispatch_action_config._resolve()
            )
        if self.focus_on_load:
            email_input["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            email_input["placeholder"] = self.placeholder._resolve()
        return email_input

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 Optional[int]

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

None
initial_options Optional[Union[Option, List[Option], OptionGroup, List[OptionGroup]]]

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

None
confirm ConfirmationDialogue

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

None
max_selected_items Optional[int]

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 Optional[TextLike]

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
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
645
646
647
648
649
650
651
652
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`](/reference/objects/#objects.Option)
            to be intially 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: Optional[int] = None,
        initial_options: Optional[
            Union[Option, List[Option], OptionGroup, List[OptionGroup]]
        ] = None,
        confirm: ConfirmationDialogue = None,
        max_selected_items: Optional[int] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = 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, 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]:
        external_select_menu = self._attributes()
        external_select_menu["action_id"] = self.action_id
        if self.min_query_length:
            external_select_menu["min_query_length"] = self.min_query_length
        if self.initial_options:
            external_select_menu["initial_options"] = [
                initial_option._resolve() for initial_option in self.initial_options
            ]
        if self.confirm:
            external_select_menu["confirm"] = self.confirm._resolve()
        if self.max_selected_items:
            external_select_menu["max_selected_items"] = self.max_selected_items
        if self.focus_on_load:
            external_select_menu["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            external_select_menu["placeholder"] = self.placeholder._resolve()
        return external_select_menu

ExternalSelectMenu

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

See: https://api.slack.com/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 Union[Option, OptionGroup]

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

None
min_query_length Optional[int]

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

None
confirm Optional[ConfirmationDialogue]

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 Optional[TextLike]

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
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
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
class ExternalSelectMenu(Element):
    """
    A select menu interactive UI element, sourced with externally provided options.

    See: <https://api.slack.com/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`](/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: Union[Option, OptionGroup] = None,
        min_query_length: Optional[int] = None,
        confirm: Optional[ConfirmationDialogue] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = 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]:
        external_select_menu = self._attributes()
        external_select_menu["action_id"] = self.action_id
        if self.initial_option:
            external_select_menu["initial_option"] = self.initial_option._resolve()
        if self.min_query_length is not None:
            external_select_menu["min_query_length"] = self.min_query_length
        if self.confirm:
            external_select_menu["confirm"] = self.confirm._resolve()
        if self.focus_on_load:
            external_select_menu["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            external_select_menu["placeholder"] = self.placeholder._resolve()
        return external_select_menu

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 Optional[str]

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

None
filetypes Optional[Union[str, List[str]]]

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

None
max_files Optional[int]

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
367
368
369
370
371
372
373
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
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: Optional[str] = None,
        filetypes: Optional[Union[str, List[str]]] = None,
        max_files: Optional[int] = None,
    ) -> "FileInput":
        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]:
        file_input = super()._resolve()
        if self.action_id is not None:
            file_input["action_id"] = self.action_id
        if self.filetypes is not None:
            file_input["filetypes"] = self.filetypes
        if self.max_files is not None:
            file_input["max_files"] = self.max_files
        return file_input

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 Optional[str]

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

None
slack_file Optional[SlackFile]

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
412
413
414
415
416
417
418
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
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`](/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: Optional[str] = None,
        slack_file: Optional[SlackFile] = None,
    ):
        super().__init__(type_=ElementType.IMAGE)
        if image_url is None and slack_file is None:
            raise InvalidUsageError("Must provide one of `image_url` or `slack_file`")
        if image_url and slack_file:
            raise InvalidUsageError("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]:
        image = self._attributes()
        if self.image_url is not None:
            image["image_url"] = self.image_url
        image["alt_text"] = self.alt_text
        if self.slack_file is not None:
            image["slack_file"] = self.slack_file
        return image

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 Optional[str]

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

None
initial_value Optional[str]

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

None
min_value Optional[Union[float, int]]

minimum accepted value for the input field.

None
max_value Optional[Union[float, int]]

maximum accepted value for the input field.

None
dispatch_action_config Optional[DispatchActionConfiguration]

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 Optional[TextLike]

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
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
912
913
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
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: Optional[str] = None,
        initial_value: Optional[str] = None,
        min_value: Optional[Union[float, int]] = None,
        max_value: Optional[Union[float, int]] = None,
        dispatch_action_config: Optional[DispatchActionConfiguration] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = 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:
            if not is_decimal_allowed:
                if isinstance(min_value, float):
                    raise InvalidUsageError(
                        f"`min_value` ({min_value}) cannot be a float when "
                        "`is_decimal_allowed` is `False`"
                    )
        if max_value:
            if not is_decimal_allowed:
                if isinstance(max_value, float):
                    raise InvalidUsageError(
                        f"`max_value` ({max_value}) cannot be a float when "
                        "`is_decimal_allowed` is `False`"
                    )
        if (min_value or min_value == 0) and (max_value or max_value == 0):
            if min_value > max_value:
                raise InvalidUsageError(
                    f"`min_value` ({min_value}) cannot be greater than "
                    "`max_value` ({min_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]:
        number_input = self._attributes()
        number_input["is_decimal_allowed"] = self.is_decimal_allowed
        if self.action_id:
            number_input["action_id"] = self.action_id
        if self.initial_value:
            number_input["initial_value"] = self.initial_value
        if self.min_value:
            number_input["min_value"] = self.min_value
        if self.max_value:
            number_input["max_value"] = self.max_value
        if self.dispatch_action_config:
            number_input["dispatch_action_config"] = (
                self.dispatch_action_config._resolve()
            )
        if self.focus_on_load:
            number_input["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            number_input["placeholder"] = self.placeholder._resolve()
        return number_input

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 Union[Option, List[Option]]

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

required
confirm ConfirmationDialogue

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
946
947
948
949
950
951
952
953
954
955
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
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`](/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: Union[Option, List[Option]],
        confirm: ConfirmationDialogue = 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]:
        overflow_menu = self._attributes()
        overflow_menu["action_id"] = self.action_id
        overflow_menu["options"] = [option._resolve() for option in self.options]
        if self.confirm:
            overflow_menu["confirm"] = self.confirm._resolve()
        return overflow_menu

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 Optional[str]

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 Optional[int]

minimum number of characters to accept as input.

None
max_length Optional[int]

maximum number of characters to accept as input.

None
dispatch_action_config Optional[DispatchActionConfiguration]

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 Optional[TextLike]

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
 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
1021
1022
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
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: Optional[str] = None,
        multiline: bool = False,
        min_length: Optional[int] = None,
        max_length: Optional[int] = None,
        dispatch_action_config: Optional[DispatchActionConfiguration] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = 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 InvalidUsageError("`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]:
        plain_text_input = self._attributes()
        if self.multiline:
            plain_text_input["multiline"] = self.multiline
        if self.action_id:
            plain_text_input["action_id"] = self.action_id
        if self.initial_value:
            plain_text_input["initial_value"] = self.initial_value
        if self.min_length:
            plain_text_input["min_length"] = self.min_length
        if self.max_length:
            plain_text_input["max_length"] = self.max_length
        if self.dispatch_action_config:
            plain_text_input["dispatch_action_config"] = (
                self.dispatch_action_config._resolve()
            )
        if self.focus_on_load:
            plain_text_input["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            plain_text_input["placeholder"] = self.placeholder._resolve()
        return plain_text_input

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 Optional[Option]

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

None
confirm Optional[ConfirmationDialogue]

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
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
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
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`](/reference/objects/#objects.Option) objects that will form
            the content of the radio button group.
        initial_option: an
            [`Option`](/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: Optional[Option] = None,
        confirm: Optional[ConfirmationDialogue] = None,
        focus_on_load: bool = False,
    ):
        super().__init__(type_=ElementType.RADIO_BUTTON_GROUP)
        self.action_id = validate_action_id(action_id)
        if len(options) < 1 or len(options) > 10:
            raise InvalidUsageError(
                "Number of options to RadioButtonGroup must be between 1 and 10 (inclusive)."
            )
        self.options = coerce_to_list(options, class_=Option, allow_none=False)
        if initial_option is not None and initial_option not in options:
            raise InvalidUsageError("`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]:
        radio_button_group = self._attributes()
        radio_button_group["action_id"] = self.action_id
        radio_button_group["options"] = [option._resolve() for option in self.options]
        if self.initial_option:
            radio_button_group["initial_option"] = self.initial_option._resolve()
        if self.confirm:
            radio_button_group["confirm"] = self.confirm._resolve()
        if self.focus_on_load:
            radio_button_group["focus_on_load"] = self.focus_on_load
        return radio_button_group

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 Optional[RichText]

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

None
dispatch_action_config Optional[DispatchActionConfiguration]

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 Optional[TextLike]

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
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
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: Optional[RichText] = None,
        dispatch_action_config: Optional[DispatchActionConfiguration] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = None,
    ) -> "RichTextInput":
        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 = placeholder

    def _resolve(self) -> Dict[str, Any]:
        rich_text_input = super()._attributes()
        rich_text_input["action_id"] = self.action_id
        if self.initial_value is not None:
            rich_text_input["initial_value"] = self.initial_value._resolve()
        if self.dispatch_action_config is not None:
            rich_text_input["dispatch_action_config"] = self.dispatch_action_config
        if self.focus_on_load is not None:
            rich_text_input["focus_on_load"] = self.focus_on_load
        if self.placeholder is not None:
            rich_text_input["placeholder"] = self.placeholder
        return rich_text_input

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 Union[Option, List[Option]]

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

required
option_groups List[OptionGroup]

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

None
initial_options Optional[Union[Option, List[Option], OptionGroup, List[OptionGroup]]]

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

None
confirm ConfirmationDialogue

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

None
max_selected_items Optional[int]

the

None
focus_on_load bool

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

False
placeholder Optional[TextLike]

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
459
460
461
462
463
464
465
466
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
578
579
580
581
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`](/reference/objects/#objects.Option)
            (max 100). Only one of `options` or `option_groups` must be
            provided.
        option_groups: a list of
            [`OptionGroups`](/reference/objects/#objects.OptionGroup)
            (max 100). Only one of `options` or `option_groups` can be
            provided.
        initial_options: the [`Options`](/reference/objects/#objects.Option)
            to be intially 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: Union[Option, List[Option]],
        option_groups: List[OptionGroup] = None,
        initial_options: Optional[
            Union[Option, List[Option], OptionGroup, List[OptionGroup]]
        ] = None,
        confirm: ConfirmationDialogue = None,
        max_selected_items: Optional[int] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = None,
    ):
        super().__init__(type_=ElementType.MULTI_SELECT_STATIC)
        self.action_id = validate_action_id(action_id)
        if options and option_groups:
            raise InvalidUsageError(
                "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, 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 InvalidUsageError(
                "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 InvalidUsageError(
                "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
        if self.options:
            options_to_validate = self.options
        if self.option_groups:
            options_to_validate = sum(
                [option_group.options for option_group in option_groups], []
            )
        for option in options_to_validate:
            if option.text.text_type == TextType.MARKDOWN:
                raise InvalidUsageError(
                    "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]:
        static_multi_select = self._attributes()
        static_multi_select["action_id"] = self.action_id
        if self.options:
            static_multi_select["options"] = [
                option._resolve() for option in self.options
            ]
        if self.option_groups:
            static_multi_select["option_groups"] = [
                option_group._resolve() for option_group in self.option_groups
            ]
        if self.initial_options:
            static_multi_select["initial_options"] = [
                initial_option._resolve() for initial_option in self.initial_options
            ]
        if self.confirm:
            static_multi_select["confirm"] = self.confirm._resolve()
        if self.max_selected_items:
            static_multi_select["max_selected_items"] = self.max_selected_items
        if self.focus_on_load:
            static_multi_select["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            static_multi_select["placeholder"] = self.placeholder._resolve()
        return static_multi_select

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]

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

None
option_groups List[OptionGroup]

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

None
initial_option Optional[Union[Option, OptionGroup]]

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

None
confirm Optional[ConfirmationDialogue]

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 Optional[TextLike]

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
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
1177
1178
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
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`](/reference/objects/#objects.Option) objects that will form
            the content of the menu (max 100).
        option_groups: a list of
            [`OptionGroups`](/reference/objects/#objects.OptionGroup)
            (max 100). Only one of `options` or `option_groups` can be
            provided.
        initial_option: an
            [`Option`](/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,
        option_groups: List[OptionGroup] = None,
        initial_option: Optional[Union[Option, OptionGroup]] = None,
        confirm: Optional[ConfirmationDialogue] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = None,
    ):
        super().__init__(type_=ElementType.STATIC_SELECT_MENU)
        self.action_id = validate_action_id(action_id)
        if options and option_groups:
            raise InvalidUsageError(
                "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
        )
        if options and initial_option and not isinstance(initial_option, Option):
            raise InvalidUsageError(
                "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 InvalidUsageError(
                "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
        if self.options:
            options_to_validate = self.options
        if self.option_groups:
            options_to_validate = sum(
                [option_group.options for option_group in option_groups], []
            )
        for option in options_to_validate:
            if option.text.text_type == TextType.MARKDOWN:
                raise InvalidUsageError(
                    "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]:
        static_select_menu = self._attributes()
        static_select_menu["action_id"] = self.action_id
        if self.options:
            static_select_menu["options"] = [
                option._resolve() for option in self.options
            ]
        if self.option_groups:
            static_select_menu["option_groups"] = [
                option_group._resolve() for option_group in self.option_groups
            ]
        if self.initial_option:
            static_select_menu["initial_option"] = self.initial_option._resolve()
        if self.confirm:
            static_select_menu["confirm"] = self.confirm._resolve()
        if self.focus_on_load:
            static_select_menu["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            static_select_menu["placeholder"] = self.placeholder._resolve()
        return static_select_menu

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 Optional[str]
None
confirm Optional[ConfirmationDialogue]

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 Optional[TextLike]

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

None
timezone Optional[str]

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
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
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
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: Optional[str] = None,
        confirm: Optional[ConfirmationDialogue] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = None,
        timezone: Optional[str] = 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]:
        time_picker = self._attributes()
        time_picker["action_id"] = self.action_id
        if self.initial_time:
            time_picker["initial_time"] = self.initial_time
        if self.confirm:
            time_picker["confirm"] = self.confirm
        if self.focus_on_load:
            time_picker["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            time_picker["placeholder"] = self.placeholder._resolve()
        if self.timezone is not None:
            time_picker["timezone"] = self.timezone
        return time_picker

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 Optional[str]

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

None
dispatch_action_config Optional[DispatchActionConfiguration]

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 Optional[TextLike]

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
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
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: Optional[str] = None,
        dispatch_action_config: Optional[DispatchActionConfiguration] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = 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]:
        url_input = self._attributes()
        url_input["action_id"] = self.action_id
        if self.initial_value is not None:
            url_input["initial_value"] = self.initial_value
        if self.dispatch_action_config:
            url_input["dispatch_action_config"] = self.dispatch_action_config._resolve()
        if self.focus_on_load:
            url_input["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            url_input["placeholder"] = self.placeholder
        return url_input

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 Optional[List[str]]

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

None
confirm ConfirmationDialogue

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

None
max_selected_items Optional[int]

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 Optional[TextLike]

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
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
702
703
704
705
706
707
708
709
710
711
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 intially 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: Optional[List[str]] = None,
        confirm: ConfirmationDialogue = None,
        max_selected_items: Optional[int] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = None,
    ):
        super().__init__(type_=ElementType.MULTI_SELECT_USERS)
        self.action_id = validate_action_id(action_id)
        self.initial_users = 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]:
        user_multi_select = self._attributes()
        user_multi_select["action_id"] = self.action_id
        if self.initial_users:
            user_multi_select["initial_users"] = self.initial_users
        if self.confirm:
            user_multi_select["confirm"] = self.confirm._resolve()
        if self.max_selected_items:
            user_multi_select["max_selected_items"] = self.max_selected_items
        if self.focus_on_load:
            user_multi_select["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            user_multi_select["placeholder"] = self.placeholder._resolve()
        return user_multi_select

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 Optional[str]

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

None
confirm Optional[ConfirmationDialogue]

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 Optional[TextLike]

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
1286
1287
1288
1289
1290
1291
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
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: Optional[str] = None,
        confirm: Optional[ConfirmationDialogue] = None,
        focus_on_load: bool = False,
        placeholder: Optional[TextLike] = 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]:
        user_select_menu = self._attributes()
        user_select_menu["action_id"] = self.action_id
        if self.initial_user:
            user_select_menu["initial_user"] = self.initial_user
        if self.confirm:
            user_select_menu["confirm"] = self.confirm._resolve()
        if self.focus_on_load:
            user_select_menu["focus_on_load"] = self.focus_on_load
        if self.placeholder:
            user_select_menu["placeholder"] = self.placeholder._resolve()
        return user_select_menu

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 Optional[Workflow]

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

None
style Optional[ButtonStyleLike]

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

DEFAULT
accessibility_label Optional[str]

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
1619
1620
1621
1622
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
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`](/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: Optional[Workflow] = None,
        style: Optional[ButtonStyleLike] = ButtonStyle.DEFAULT,
        accessibility_label: Optional[str] = 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]:
        workflow_button = self._attributes()
        workflow_button["text"] = self.text._resolve()
        if self.workflow:
            workflow_button["workflow"] = self.workflow._resolve()
        if self.style is not None:
            workflow_button["style"] = self.style
        if self.accessibility_label:
            workflow_button["accessibility_label"] = self.accessibility_label
        return workflow_button