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
| Argument | Type | Description |
|---|---|---|
elements | Optional[List[Element]] | a list of Elements (up to a maximum of 25). |
block_id | Optional[str] | you can use this field to provide a deterministic identifier for the block. |
Errors
| Error | When |
|---|---|
InvalidUsageError | if 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
| Argument | Type | Description |
|---|---|---|
elements | Optional[List[Union[Element, CompositionObject]]] | a list of Text objects and Image elements. |
block_id | Optional[str] | you can use this field to provide a deterministic identifier for the block. |
Errors
| Error | When |
|---|---|
InvalidUsageError | when 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
| Argument | Type | Description |
|---|---|---|
block_id | Optional[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
| Argument | Type | Description |
|---|---|---|
external_id | str | the ID assigned to the remote file when it was added to Slack. |
block_id | Optional[str] | you can use this field to provide a deterministic identifier for the block. |
source | str | always "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
| Argument | Type | Description |
|---|---|---|
text | Union[str, Text] | the text that will be rendered as a heading. |
block_id | Optional[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
| Argument | Type | Description |
|---|---|---|
image_url | str | the URL pointing to the image file you want to display. |
alt_text | Optional[str] | alternative text for accessibility purposes and when the image fails to load. |
title | Optional[Union[Text, str]] | an optional text title to be presented with the image. |
block_id | Optional[str] | you can use this field to provide a deterministic identifier for the block. |
Errors
| Error | When |
|---|---|
InvalidUsageError | when 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
| Argument | Type | Description |
|---|---|---|
label | TextLike | the name which identifies the input field. |
element | Element | an interactive Element (e.g. a text field). |
dispatch_action | bool | whether the Element should trigger the sending of a block_actions payload. |
block_id | Optional[str] | you can use this field to provide a deterministic identifier for the block. |
hint | Optional[TextLike] | an optional additional guide on what input the user should prodive. |
optional | bool | whether this input field may be empty when the user submits e.g. the modal. |
Errors
| Error | When |
|---|---|
InvalidUsageError | when 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
| Argument | Type | Description |
|---|---|---|
elements | Union[RichTextObject, List[RichTextObject]] | a single rich text element or a list of those elements. |
block_id | Optional[str] | you can use this field to provide a deterministic identifier for the block. |
Errors
| Error | When |
|---|---|
InvalidUsageError | if the elements in elements are not valid richtext 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
| Argument | Type | Description |
|---|---|---|
text | Optional[TextLike] | text to include in the block. Can be a string or Text object (of eithermrkdwn or plaintext variety). Defaults to markdown if unspecified. One of eithertext or fields must be provided. |
block_id | Optional[str] | you can use this field to provide a deterministic identifier for the block. |
fields | Optional[Union[TextLike, List[TextLike]]] | a list of text objects. One of either text or fields must be provided. |
accessory | Optional[Element] | an optional Element object that will take a secondary place in the block (after or to the side of text or fields). |
Errors
| Error | When |
|---|---|
InvalidUsageError | if any of the provided arguments fail validation checks. |