Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slack API invalid_block

Tags:

slack-api

I'm building a simple slack bot and I am playing with the checkboxes element.

When I return the following from my API in a JSON response to a slash-command I get an error failed with the error "invalid_blocks", however, when I put this in the block-kit-builder it works perfectly (including "sending to slack" button)

Any ideas why this is failing when I run my slash command - and is it possible to see more detailed error messages from slack?

{
  "blocks": [
    {
      "elements": [
        {
          "style": "primary",
          "text": {
            "emoji": true,
            "text": "Create new TODO list",
            "type": "plain_text"
          },
          "type": "button",
          "value": "value"
        },
        {
          "style": "primary",
          "text": {
            "emoji": true,
            "text": "Help",
            "type": "plain_text"
          },
          "type": "button",
          "value": "value"
        }
      ],
      "type": "actions"
    },
    {
      "text": {
        "text": "Today",
        "type": "mrkdwn"
      },
      "type": "section"
    },
    {
      "elements": [
        {
          "initial_options": [
            {
              "text": {
                "text": "Get Into the garden",
                "type": "mrkdwn"
              },
              "value": "foo"
            }
          ],
          "options": [
            {
              "text": {
                "text": "Get Into the garden",
                "type": "mrkdwn"
              },
              "value": "foo"
            }
          ],
          "type": "checkboxes"
        },
        {
          "style": "primary",
          "text": {
            "emoji": true,
            "text": "Add new Task",
            "type": "plain_text"
          },
          "type": "button",
          "value": "value"
        }
      ],
      "type": "actions"
    }
  ],
  "type": "home"
}
like image 662
Ben Flowers Avatar asked Nov 27 '25 21:11

Ben Flowers


2 Answers

I kept getting the invalid_blocks error. It turned out that the Slack API seems to have a pretty arbitrary limit of 2958 characters in the text block (using markdown). It seems like a very odd number, so maybe it's some combination of the total size of the json body. In any case if it's not working try decreasing the size of the text.

like image 51
foges Avatar answered Nov 29 '25 10:11

foges


Another cause of this problem seems to be too many blocks being returned. I can't find any documentation about this whatsoever, but personal experience seems to indicate about 20 blocks is the maximum.

An alternative is to return fewer blocks, with paging actions -- paging works well with the "replace" message so that the content being paged through does not result in many separate messages.

like image 28
Raman Avatar answered Nov 29 '25 11:11

Raman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!