Skip to main content

Colored-bar attachment

Use a legacy attachment when an existing integration needs a colored side bar. Prefer regular blocks for new layouts.

Output

Local preview of the selected language’s tested example. Slack client appearance may differ; controls here do not send requests.

Disk usage warning
⚠️ /var is at 87% capacity on prod-db-1.
Serialized output
{
"channel": "#alerts",
"mrkdwn": true,
"attachments": [
{
"blocks": [
{
"type": "section",
"block_id": "<generated-block-id>",
"text": {
"type": "mrkdwn",
"text": ":warning: `/var` is at 87% capacity on `prod-db-1`."
}
}
],
"color": "#ffff00"
}
],
"text": "Disk usage warning"
}

Code​

Slack has long deprecated message attachments, but they're still the only way to get the colored vertical bar on the left of a message. slackblocks supports them when you really need that styling:

from slackblocks import (
Attachment,
Color,
Message,
SectionBlock,
)

msg = Message(
channel="#alerts",
text="Disk usage warning",
attachments=[
Attachment(
color=Color.YELLOW,
blocks=[SectionBlock(":warning: `/var` is at 87% capacity on `prod-db-1`.")],
),
],
)
print(msg.json())

Prefer plain blocks where possible — Slack may drop attachment support in the future.