Skip to main content

Attachments

Attachment

Class

Attachment(blocks: 'Block | list[Block] | None' = None, color: 'str | Color | None' = None, fields: 'Field | list[Field] | None' = None, fallback: 'str | None' = 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
blocksBlock | list[Block] | Nonean array of Blocks that define the content of the attachment.
colorstr | Color | Nonethe 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.
fieldsField | list[Field] | Nonea list of Field objects to be included in what's rendered in the attachment.
fallbackstr | NoneA plain text summary of the attachment used in clients that don't show
formatted text (eg. IRC, mobile notifications).

Errors

ErrorWhen
InvalidUsageErrorif the color code provided is invalid.

Color

Class

Color(*values)

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

Pass these to the color argument of Attachment.

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

Field

Class

Field(title: 'str | None' = None, value: 'str | None' = None, short: 'bool | None' = False)

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

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

Arguments

ArgumentTypeDescription
titlestr | Nonetext shown as a bold heading on the field.
valuestr | Nonetext (mrkdwn or plaintext) representing the value of the field.
shortbool | Nonewhether the contents of the field is short enough to be presented in
multipe columns.