layout_block¶
Blocks are a series of components that can be combined to create visually rich and compellingly interactive messages.
Read our guide to building block layouts to learn where and how to use each of these components. You can include up to 50 blocks in each message, and 100 blocks in modals or home tabs.
You can see the full Slack documentation on layout blocks to see examples and the most up-to-date styling information.
Note
A block_id
can be specified for all layout block objects. If one is not specified, a randomly-generated UUID (v4)
will be assigned. UUID v1 poses security risks as it exposes the MAC address of the server. For more about the
differences in the 2 versions, read this blog.
LayoutBlock¶
-
class
slack_blockkit.layout_block.
LayoutBlock
(btype: str, block_id: str = None)¶ Defines a basic layout block. For more information, see: https://api.slack.com/reference/block-kit/blocks
- Parameters
btype (str) – Synonymous with Slack’s
type
parameter.block_id (str) –
A string acting as a unique identifier for a block. You can use this
block_id
when you receive an interaction payload to identify the source of the action. If not specified, ablock_id
will be generated. Maximum length for this field is 255 characters.If not
block_id
is specified, ablock_id
is set to a random UUID v4.
-
static
generate_block_id
() → str¶ Generates a UUID (v4) to be used as a block ID.
- Returns
A random UUID (v4) as a string.
- Return type
str
ActionsBlock¶
-
class
slack_blockkit.layout_block.
ActionsBlock
(elements: List[slack_blockkit.block_element.BlockElement], block_id: str = None)¶ A block that is used to hold interactive elements. For more information, see: https://api.slack.com/reference/block-kit/blocks#actions
- Parameters
elements (List[BlockElement]) – An array of interactive element objects - buttons, select menus, overflow menus, or date pickers. There is a maximum of 5 elements in each action block.
block_id (str) – A string acting as a unique identifier for a block. You can use this
block_id
when you receive an interaction payload to identify the source of the action. If not specified, ablock_id
will be generated. Maximum length for this field is 255 characters.
ContextBlock¶
-
class
slack_blockkit.layout_block.
ContextBlock
(elements: list, block_id: str = None)¶ Displays message context, which can include both images and text. For more information, see: https://api.slack.com/reference/block-kit/blocks#context
- Parameters
elements (List[BlockElement]) – An array of
ImageElement
andTextObjects
. Maximum number of items is 10.block_id (str) – A string acting as a unique identifier for a block. You can use this
block_id
when you receive an interaction payload to identify the source of the action. If not specified, ablock_id
will be generated. Maximum length for this field is 255 characters.
DividerBlock¶
-
class
slack_blockkit.layout_block.
DividerBlock
(block_id: str = None)¶ A content divider, like an
<hr>
, to split up different blocks inside of a message. The divider block is nice and neat, requiring only a type.For more information, see: https://api.slack.com/reference/block-kit/blocks#divider- Parameters
block_id (str) – A string acting as a unique identifier for a block. You can use this
block_id
when you receive an interaction payload to identify the source of the action. If not specified, ablock_id
will be generated. Maximum length for this field is 255 characters.
FileBlock¶
-
class
slack_blockkit.layout_block.
FileBlock
(external_id: str, source: str = 'remote', block_id: str = None)¶ Displays a remote file. For more information, see: https://api.slack.com/reference/block-kit/blocks#file
- Parameters
external_id (str) – The external unique ID for this file.
source (str) – At the moment,
source
will always be remote for a remote file.block_id (str) – A string acting as a unique identifier for a block. You can use this
block_id
when you receive an interaction payload to identify the source of the action. If not specified, ablock_id
will be generated. Maximum length for this field is 255 characters.
ImageBlock¶
-
class
slack_blockkit.layout_block.
ImageBlock
(image_url: str, alt_text: str, title: slack_blockkit.composition_object.TextObject = None, block_id: str = None)¶ A simple image block, designed to make those cat photos really pop. For more information, see: https://api.slack.com/reference/block-kit/blocks#image
- Parameters
image_url (str) – The URL of the image to be displayed. Maximum length for this field is 3000 characters.
alt_text (str) – A plain-text summary of the image. This should not contain any markup. Maximum length for this field is 2000 characters.
title (TextObject) – An optional title for the image in the form of a
TextObject
that can only be of type:plain_text
. Maximum length for the text in this field is 2000 characters.block_id (str) – A string acting as a unique identifier for a block. You can use this
block_id
when you receive an interaction payload to identify the source of the action. If not specified, ablock_id
will be generated. Maximum length for this field is 255 characters.
InputBlock¶
-
class
slack_blockkit.layout_block.
InputBlock
(label: slack_blockkit.composition_object.TextObject, element: slack_blockkit.block_element.BlockElement, block_id: str = None, hint: slack_blockkit.composition_object.TextObject = None, optional: bool = False)¶ A block that collects information from users - it can hold a plain-text input element, a select menu element, a multi-select menu element, or a datepicker. For more information, see: https://api.slack.com/reference/block-kit/blocks#input
- Parameters
label (TextObject) – A label that appears above an input element in the form of a
TextObject
that must have type ofplain_text
. Maximum length for the text in this field is 2000 characters.element (BlockElement) – An plain-text input element, a select menu element, a multi-select menu element, or a datepicker.
block_id (str) – A string acting as a unique identifier for a block. You can use this
block_id
when you receive an interaction payload to identify the source of the action. If not specified, ablock_id
will be generated. Maximum length for this field is 255 characters.hint (TextObject) – An optional hint that appears below an input element in a lighter grey. It must be a
TextObject
with a type ofplain_text
. Maximum length for the text in this field is 2000 characters.optional (bool) – A boolean that indicates whether the input element may be empty when a user submits the modal. Defaults to
False
.
SectionBlock¶
-
class
slack_blockkit.layout_block.
SectionBlock
(text: slack_blockkit.composition_object.TextObject, block_id: str = None, fields: List[slack_blockkit.composition_object.TextObject] = None, accessory: slack_blockkit.block_element.BlockElement = None)¶ Basic section block. For more information, see: https://api.slack.com/reference/block-kit/blocks#section
- Parameters
text (TextObject) – The text for the block, in the form of a
TextObject
. Maximum length for the text in this field is 3000 characters. This field is not required if a valid array of fields objects is provided instead.block_id (str) – A string acting as a unique identifier for a block. You can use this
block_id
when you receive an interaction payload to identify the source of the action. If not specified, ablock_id
will be generated. Maximum length for this field is 255 characters.fields (List[TextObject]) – An array of
TextObject
. Any text objects included with fields will be rendered in a compact format that allows for 2 columns of side-by-side text. Maximum number of items is 10. Maximum length for the text in each item is 2000 characters.accessory (BlockElement) – One of the available
ElementObject
.