block_element¶
Block elements can be used inside of section
, context
, and actions
layout blocks.
Inputs can only be used inside of input blocks.
This overview of app surfaces that support Block Kit shows you where add blocks.
Finally, our handling user interactivity guide will help you prepare your app to allow for the use of the interactive components listed below.
You can see the full Slack documentation on block elements to see examples and the most up-to-date styling information.
BlockElement¶
-
class
slack_blockkit.block_element.
BlockElement
(btype: str, action_id: str = None)¶ Defines a basic block element. For more information, see: https://api.slack.com/reference/block-kit/block-elements
- Parameters
btype (str) – Synonymous with Slack’s
type
parameter.action_id (str) – The unique action ID.
ButtonElement¶
-
class
slack_blockkit.block_element.
ButtonElement
(text: slack_blockkit.composition_object.TextObject, action_id: str, url: str = None, value: str = None, style: str = 'default', confirm: slack_blockkit.composition_object.ConfirmObject = None)¶ An interactive component that inserts a button. The button can be a trigger for anything from opening a simple link to starting a complex workflow. For more information, see: https://api.slack.com/reference/block-kit/block-elements#button
- Parameters
text (TextObject) – A text object that defines the button’s text. Can only be of type: plain_text. Maximum length for the text in this field is 75 characters.
action_id (str) – An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action. Should be unique among all other action_ids used elsewhere by your app. Maximum length for this field is 255 characters.
url (str) – A URL to load in the user’s browser when the button is clicked. Maximum length for this field is 3000 characters. If you’re using url, you’ll still receive an interaction payload and will need to send an acknowledgement response.
value (str) – The value to send along with the interaction payload. Maximum length for this field is 2000 characters.
style (str) –
Decorates buttons with alternative visual color schemes. Use this option with restraint.
primary
gives buttons a green outline and text, ideal for affirmation or confirmation actions.primary
should only be used for one button within a set.danger
gives buttons a red outline and text, and should be used when the action is destructive. Usedanger
even more sparingly than primary.If you don’t include this field, the
default
button style will be used.
PrimaryButtonElement¶
-
class
slack_blockkit.block_element.
PrimaryButtonElement
(text: slack_blockkit.composition_object.TextObject, action_id: str, url: str = None, value: str = None, confirm: slack_blockkit.composition_object.ConfirmObject = None)¶ A
ButtonElement
whosestyle
isprimary
.- Parameters
text (TextObject) – A text object that defines the button’s text. Can only be of type: plain_text. Maximum length for the text in this field is 75 characters.
action_id (str) – An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action. Should be unique among all other action_ids used elsewhere by your app. Maximum length for this field is 255 characters.
url (str) – A URL to load in the user’s browser when the button is clicked. Maximum length for this field is 3000 characters. If you’re using url, you’ll still receive an interaction payload and will need to send an acknowledgement response.
value (str) – The value to send along with the interaction payload. Maximum length for this field is 2000 characters.
DangerButtonElement¶
-
class
slack_blockkit.block_element.
DangerButtonElement
(text: slack_blockkit.composition_object.TextObject, action_id: str, url: str = None, value: str = None, confirm: slack_blockkit.composition_object.ConfirmObject = None)¶ A
ButtonElement
whosestyle
isdanger
.- Parameters
text (TextObject) – A text object that defines the button’s text. Can only be of type: plain_text. Maximum length for the text in this field is 75 characters.
action_id (str) – An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action. Should be unique among all other action_ids used elsewhere by your app. Maximum length for this field is 255 characters.
url (str) – A URL to load in the user’s browser when the button is clicked. Maximum length for this field is 3000 characters. If you’re using url, you’ll still receive an interaction payload and will need to send an acknowledgement response.
value (str) – The value to send along with the interaction payload. Maximum length for this field is 2000 characters.
DefaultButtonElement¶
-
class
slack_blockkit.block_element.
DefaultButtonElement
(text: slack_blockkit.composition_object.TextObject, action_id: str, url: str = None, value: str = None, confirm: slack_blockkit.composition_object.ConfirmObject = None)¶ A
ButtonElement
whosestyle
isdefault
.- Parameters
text (TextObject) – A text object that defines the button’s text. Can only be of type: plain_text. Maximum length for the text in this field is 75 characters.
action_id (str) – An identifier for this action. You can use this when you receive an interaction payload to identify the source of the action. Should be unique among all other action_ids used elsewhere by your app. Maximum length for this field is 255 characters.
url (str) – A URL to load in the user’s browser when the button is clicked. Maximum length for this field is 3000 characters. If you’re using url, you’ll still receive an interaction payload and will need to send an acknowledgement response.
value (str) – The value to send along with the interaction payload. Maximum length for this field is 2000 characters.
DatepickerElement¶
-
class
slack_blockkit.block_element.
DatepickerElement
(action_id: str, placeholder: slack_blockkit.composition_object.TextObject, initial_date: str = None, confirm: slack_blockkit.composition_object.ConfirmObject = None)¶ An element which lets users easily select a date from a calendar style UI. For more information, see: https://api.slack.com/reference/block-kit/block-elements#datepicker
- Parameters
action_id (str) – An identifier for the action triggered when a menu option is selected. You can use this when you receive an interaction payload to identify the source of the action. Should be unique among all other action_ids used elsewhere by your app. Maximum length for this field is 255 characters.
placeholder (TextObject) – A
plain_text
only text object that defines the placeholder text shown on the datepicker. Maximum length for the text in this field is 150 characters.initial_date (str) – The initial date that is selected when the element is loaded. This should be in the format
YYYY-MM-DD
.confirm (ConfirmObject) – A
ConfirmObject
that defines an optional confirmation dialog that appears after a date is selected.
ImageElement¶
-
class
slack_blockkit.block_element.
ImageElement
(image_url: str, alt_text: str)¶ An element to insert an image as part of a larger block of content. If you want a block with only an image in it, you’re looking for the image block. For more information, see: https://api.slack.com/reference/block-kit/block-elements#image
- Parameters
image_url (str) – The URL of the image to be displayed.
alt_text (str) – A plain-text summary of the image. This should not contain any markup.
OverflowElement¶
-
class
slack_blockkit.block_element.
OverflowElement
(action_id: str, options: List[slack_blockkit.composition_object.OptionObject], confirm: slack_blockkit.composition_object.ConfirmObject = None)¶ This is like a cross between a button and a select menu - when a user clicks on this overflow button, they will be presented with a list of options to choose from. Unlike the select menu, there is no typeahead field, and the button always appears with an ellipsis (“…”) rather than customisable text. For more information, see: https://api.slack.com/reference/block-kit/block-elements#overflow
- Parameters
action_id (str) – An identifier for the action triggered when a menu option is selected. You can use this when you receive an interaction payload to identify the source of the action. Should be unique among all other
action_id
used elsewhere by your app. Maximum length for this field is 255 characters.options (List[OptionObject]) – An array of
OptionObject
to display in the menu. Maximum number of options is 5, minimum is 2.confirm (ConfirmObject) – A
ConfirmObject
that defines an optional confirmation dialog that appears after a menu item is selected.
PlainTextInputElement¶
-
class
slack_blockkit.block_element.
PlainTextInputElement
(action_id: str, placeholder: slack_blockkit.composition_object.TextObject = None, initial_value: str = None, multiline: bool = False, min_length: int = 0, max_length: int = 0)¶ 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 textarea using the multiline flag. For more information, see: https://api.slack.com/reference/block-kit/block-elements#input
- Parameters
action_id (str) – An identifier for the action triggered when a menu option is selected. You can use this when you receive an interaction payload to identify the source of the action. Should be unique among all other
action_id
used elsewhere by your app. Maximum length for this field is 255 characters.placeholder (TextObject) – Optionall A
plain_text
only text object that defines the placeholder text shown in the plain-text input. Maximum length for the text in this field is 150 characters.initial_value (str) – Optional; The initial value in the plain-text input when it is loaded.
multiline (bool) – Optional; Indicates whether the input will be a single line (
False
) or a larger textarea (True
). Defaults toFalse
.min_length (int) – The minimum length of input that the user must provide. If the user provides less, they will receive an error. Maximum value is 3000.
max_length (int) – The maximum length of input that the user can provide. If the user provides more, they will receive an error.
RadioButtonGroupElement¶
-
class
slack_blockkit.block_element.
RadioButtonGroupElement
(action_id: str, options: List[slack_blockkit.composition_object.OptionObject], intitial_option: slack_blockkit.composition_object.OptionObject = None, confirm: slack_blockkit.composition_object.ConfirmObject = None)¶ A radio button group that allows a user to choose one item from a list of possible options. For more information, see: https://api.slack.com/reference/block-kit/block-elements#radio
- Parameters
action_id (str) – An identifier for the action triggered when a menu option is selected. You can use this when you receive an interaction payload to identify the source of the action. Should be unique among all other
action_id
used elsewhere by your app. Maximum length for this field is 255 characters.options (List[OptionObject]) – An array of
OptionObject
.initial_option (OptionObject) – An
OptionObject
that exactly matches one of the options within options. This option will be selected when the radio button group initially loads.confirm (ConfirmObject) – A
ConfirmObject
that defines an optional confirmation dialog that appears after clicking one of the radio buttons in this element.