Skip to main content

Blocks

ActionsBlock

Class

ActionsBlock(elements: Optional[List[Element]] = None, block_id: Optional[str] = None)

A Block that is used to hold interactive elements (normally for users to interface with).

Arguments

ArgumentTypeDescription
elementsOptional[List[Element]]a list of Elements (up to a maximum of 25).
block_idOptional[str]you can use this field to provide a deterministic identifier for the block.

Errors

ErrorWhen
InvalidUsageErrorif any of the items in elements are invalid.

ContextBlock

Class

ContextBlock(elements: Optional[List[Union[Element, CompositionObject]]] = None, block_id: Optional[str] = None)

A ContextBlock displays contextul message info, including both images and text.

Arguments

ArgumentTypeDescription
elementsOptional[List[Union[Element, CompositionObject]]]a list of Text objects and Image elements.
block_idOptional[str]you can use this field to provide a deterministic identifier for the block.

Errors

ErrorWhen
InvalidUsageErrorwhen items in elements are not Text or Image or exceed 10 items.

DividerBlock

Class

DividerBlock(block_id: Optional[str] = None)

A content divider, like an <hr> in HTML, to split up different blocks inside of a message.

Arguments

ArgumentTypeDescription
block_idOptional[str]you can use this field to provide a deterministic identifier for the block.

FileBlock

Class

FileBlock(external_id: str, block_id: Optional[str], source: str = 'remote')

Displays a remote file (e.g. a PDF).

For details on how remote files are exposed to Slack, see https://api.slack.com/messaging/files#adding.

Arguments

ArgumentTypeDescription
external_idstrthe ID assigned to the remote file when it was added to Slack.
block_idOptional[str]you can use this field to provide a deterministic identifier for the block.
sourcestralways "remote" as per the Slack API (may change in the future).

HeaderBlock

Class

HeaderBlock(text: Union[str, Text], block_id: Optional[str] = None)

A Header Block is a plain-text block that displays in a larger, bold font.

Arguments

ArgumentTypeDescription
textUnion[str, Text]the text that will be rendered as a heading.
block_idOptional[str]you can use this field to provide a deterministic identifier for the block.

ImageBlock

Class

ImageBlock(image_url: str, alt_text: Optional[str] = ' ', title: Optional[Union[Text, str]] = None, block_id: Optional[str] = None)

An Image Block contains a single graphic, accessed by URL.

Arguments

ArgumentTypeDescription
image_urlstrthe URL pointing to the image file you want to display.
alt_textOptional[str]alternative text for accessibility purposes and when the image fails to load.
titleOptional[Union[Text, str]]an optional text title to be presented with the image.
block_idOptional[str]you can use this field to provide a deterministic identifier for the block.

Errors

ErrorWhen
InvalidUsageErrorwhen one or more of the provided args fails validation.

InputBlock

Class

InputBlock(label: TextLike, element: Element, dispatch_action: bool = False, block_id: Optional[str] = None, hint: Optional[TextLike] = None, optional: bool = False)

A block that collects information from users - it can hold a plain-text input element, a checkbox element, a radio button element, a select menu element, a multi-select menu element, or a datepicker.

Arguments

ArgumentTypeDescription
labelTextLikethe name which identifies the input field.
elementElementan interactive Element (e.g. a text field).
dispatch_actionboolwhether the Element should trigger the
sending of a block_actions payload.
block_idOptional[str]you can use this field to provide a deterministic identifier for the block.
hintOptional[TextLike]an optional additional guide on what input the user should prodive.
optionalboolwhether this input field may be empty when the user submits e.g. the modal.

Errors

ErrorWhen
InvalidUsageErrorwhen any of the provided arguments fail validation.

RichTextBlock

Class

RichTextBlock(elements: Union[RichTextObject, List[RichTextObject]], block_id: Optional[str] = None)

A RichTextBlock is used to provide easier rich text formatting than standard markdown text (e.g. in a SectionBlock) and access to text formatting features not available in traditional markdown (e.g. strikethrough). See the various rich text elements you can include here.

Arguments

ArgumentTypeDescription
elementsUnion[RichTextObject, List[RichTextObject]]a single rich text element
or a list of those elements.
block_idOptional[str]you can use this field to provide a deterministic identifier
for the block.

Errors

ErrorWhen
InvalidUsageErrorif the elements in elements are not valid rich
text elements.

SectionBlock

Class

SectionBlock(text: Optional[TextLike] = None, block_id: Optional[str] = None, fields: Optional[Union[TextLike, List[TextLike]]] = None, accessory: Optional[Element] = None)

A section is one of the most flexible blocks available - it can be used as a simple text block, or with any of the available block elements.

Section blocks can also optionally be given an "accessory," which is typically one of the interactive Elements.

Arguments

ArgumentTypeDescription
textOptional[TextLike]text to include in the block. Can be a string or Text object (of either
mrkdwn or plaintext variety). Defaults to markdown if unspecified. One of either
text or fields must be provided.
block_idOptional[str]you can use this field to provide a deterministic identifier for the block.
fieldsOptional[Union[TextLike, List[TextLike]]]a list of text objects. One of either text or fields must be provided.
accessoryOptional[Element]an optional Element object that will take a
secondary place in the block (after or to the side of text or fields).

Errors

ErrorWhen
InvalidUsageErrorif any of the provided arguments fail validation checks.