Search code examples
slackslack-api

Slack SDK: How to add color to blocks similar to attachments


I'd like to know how to add color to slack blocks similar to attachments. In attachments I can add a color and the whole block will have a color line to the left which refine the way job output is reported.

I can do it in attachments using this code line below:

attachments=[{"color": "#FF0000" if errors else "#4BB543", "blocks": blocks}]

I want to use blocks instead as I have a file url to share and it's not rendering properly in attachments, but working well if I used blocks.

enter image description here


Solution

  • https://api.slack.com/messaging/attachments-to-blocks#direct_equivalents

    There is one exception, and that's the color parameter, which currently does not have a block alternative. If you are strongly attached (🎺) to the color bar, use the blocks parameter within an attachment.