5

I have a slack bot that uses a menu drop down, and it has a color bar on the side. See the screenshot of what I have here in the green circle

I want the bar to extend the whole message like this image
Note: This image is edited to show the example of the red bar (and because the actual slack bot message isn't important)

My code has something like

    let slackPost = {
        "blocks": [
            {
                "type": "section",
                "text": {
                    "type": "mrkdwn",
                    "text": myText
                }
            } // ... some other blocks
        ],
        "attachments": [
            {
                "text": menuTitle,
                "color": menuBarColor,
                "attachment_type": "default",
                "actions": [
                    {
                        "name": menuName,
                        "text": menuPlaceHolder,
                        "type": "select",
                        "options": menuOptions   
                    }
                ]
            }
        ]
    }
CME
  • 51
  • 1
  • 4

2 Answers2

7

The new slack blocks layout doesn't allow the old color attachments property. You can find official documentation here.

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.

Madhava Carrillo
  • 3,998
  • 3
  • 18
  • 24
5

You can nest blocks inside the attachment property, like this:

let slackPost = {
  "attachments": [{
    "color": message.color,
    "blocks": [
      {
        "type": "section",
        "text": {
          "type": "mrkdwn",
          "text": myText
        }
      } // ... some other blocks
    ]
   }]
  • 1
    This works for RGB colors (`#439FE0`), but afaict named colors (`good`, `warning`, `danger`) show up as grey when blocks are present inside an attachment. – Paul Brannan May 11 '23 at 17:52