Skip to main content

Attachments

Warning: Deprecated Feature

Attachments, while still accepted by the Slack API, have long (for years now) been considered a deprecated feature.

That said, there is currently no other way to achieve the vertical, colored bars next to content.

Attachment

Class

Attachment(blocks: Optional[Union[Block, List[Block]]] = None, color: Optional[Union[str, Color]] = None, fields: Optional[Union[Field, List[Field]]] = None)

Lower priority content can be attached to messages using Attachments. This is content that doesn't necessarily need to be seen to appreciate the intent of the message, but perhaps adds further context or additional information.

See https://api.slack.com/reference/messaging/attachments.

N.B: fields is a deprecated field, included only for legacy purposes. Other legacy fields, e.g. author_name are deliberately omitted as they were never implemented in slackblocks.

Arguments

ArgumentTypeDescription
blocksOptional[Union[Block, List[Block]]]an array of Blocks that define the content of the attachment.
colorOptional[Union[str, Color]]the color (in hex format, e.g. #ffffff) of the vertical bar to the left of the
attachment content. Consider using the Color enum from this module.
fieldsOptional[Union[Field, List[Field]]]a list of Field objects to be included in what's rendered in the attachment.

Errors

ErrorWhen
InvalidUsageErrorif the color code provided is invalid.

Color

Class

Color is a utility class for use with the Slack secondary attachments API.

Pass these to the color argument of Attachment.

Color.GOODgood
Color.WARNINGwarning
Color.DANGERdanger
Color.REDred
Color.BLUEblue
Color.YELLOWyellow
Color.GREENgreen
Color.ORANGEorange
Color.PURPLEpurple
Color.BLACKblack

Field

Class

Field(title: Optional[str] = None, value: Optional[str] = None, short: Optional[bool] = False)

Field text objects for use with Slack's secondary attachment API.

See https://api.slack.com/reference/messaging/attachments#fields.

Arguments

ArgumentTypeDescription
titleOptional[str]text shown as a bold heading on the field.
valueOptional[str]text (mrkdwn or plaintext) representing the value of the field.
shortOptional[bool]whether the contents of the field is short enough to be presented in
multipe columns.