slack-api-specs icon indicating copy to clipboard operation
slack-api-specs copied to clipboard

Block Kit support

Open seratch opened this issue 5 years ago • 13 comments

Description

The documentation already supports Block Kit. However, the changes to parameters/response are not yet reflected in this repository. Do you have any plans to work on it in the short term? If I can do something for it, I am keen to be involved in it.

What type of issue is this? (place an x in one of the [ ])

  • [ ] bug
  • [ ] enhancement (feature request)
  • [ ] question
  • [x] documentation related
  • [ ] testing related
  • [ ] discussion

Requirements (place an x in each of the [ ])

  • [x] I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • [x] I've read and agree to the Code of Conduct.
  • [x] I've searched for any related issues and avoided creating a duplicate issue.

seratch avatar Mar 10 '19 00:03 seratch

We want to offer full JSON schema (and a subset within our OpenAPI specs) for Block Kit but aren't yet ready to do so. In the meantime, the newest version of the spec on master includes a bare bones schema for blocks and includes the blocks parameter on methods that support them. Look for deeper support (including the difference between input and output blocks) in the future.

episod avatar Jul 17 '19 21:07 episod

it would be wonderful if you could open source the validation code in https://app.slack.com/block-kit-builder

simonh1000 avatar Jul 23 '20 13:07 simonh1000

Curious to see that there hasn't been any notice on this for almost four years. As far as I can see, Block Kit is still the way to go for displaying UI in Slack, right? Having no way to validate it makes for fairly poor developer experience 😕

x3ro avatar Feb 04 '23 14:02 x3ro

it's quite hard to plan an integration and be sure it will work with real data without a schema, it would be great if you could publish it.

riffraff avatar Feb 10 '23 11:02 riffraff

+1 It makes a lot of sense to add BlockKit JSON schema to OpenAPI specifications. Any news on this?

fab-mindflow avatar Apr 26 '23 04:04 fab-mindflow

Btw, it looks like this JSON schema exists: https://gist.github.com/renatorib/1fb1a9bd71435b41bee602d15bc56899

Would it be possible to share this JSON schema officially?

fab-mindflow avatar Apr 26 '23 05:04 fab-mindflow

The schema that's mentioned in the gist, and here by @fab-mindflow is incomplete, it cuts out after ~18k characters, so it's an invalid schema right now.

delanni avatar Oct 09 '23 14:10 delanni

This was first open in 2019. Can someone at Slack take a look please?

fab-mindflow avatar Oct 09 '23 20:10 fab-mindflow

Nudging this as it's super painful having to manually copy paste to the block builder website or only find out in a live system. I'd like to wrap my block generation client side in a unit test which validates the output against the JSON schema.

Given the tooling on the block kit builder has this to validate against I was hoping it's easy to publish :pray:

lawrencegripper avatar Oct 10 '23 16:10 lawrencegripper

I'm not someone at slack but took a look!

TLDR: With some manual effort and the typescript type information I semi-auto generated the schema. Here it is for others to use. Note: It validates an array of blocks for input.

 [
    {
	    "type": "header",
	    "text": {
		    "type": "plain_text",
		    "text": "some message",
		    "emoji": true
	    }
     }
]

How?:

Talking with @itoys he suggested this approach using the typescript definitions for blocks to create a schema.

Doing that over this file gave me the definitions for the block types available :partying_face:

  • https://github.com/slackapi/node-slack-sdk/blob/main/packages/types/src/block-kit/blocks.ts

I then needed a top level definition for the to match the possible different block types, I did this with if-then syntax for json schema.

    "type": "object",
    "properties": {
      "type": {
        "enum": [
          "image",
          "context",
          "actions",
          "divider",
          "section",
          "input",
          "file",
          "header",
          "video",
          "rich_text"
        ]
      }
    },
    "required": [
      "type"
    ],
    "additionalProperties": true,
    "allOf": [
      {
        "if": {
          "properties": {
            "type": {
              "const": "image"
            }
          }
        },
        "then": {
          "$ref": "#/definitions/ImageBlock"
        }
      },
      {
        "if": {
          "properties": {
            "type": {
              "const": "context"
            }
          }
        },
        "then": {
          "$ref": "#/definitions/ContextBlock"
        }
      },

lawrencegripper avatar Oct 10 '23 20:10 lawrencegripper

Thanks to @okeeffed for the typescript to json schema code and awesome blog 🙇‍♂️

lawrencegripper avatar Oct 10 '23 21:10 lawrencegripper

Stoked that it managed to help out @lawrencegripper ❤️

okeeffed avatar Oct 10 '23 23:10 okeeffed

That schema is unfortunately also incomplete; many of Slack's blocks have limits on how many elements can appear in a list (e.g. an upper limit of 100 options in a dropdown select's options field) or how long various strings can be (e.g. a 150 character limit for the text element in a header block) or even how many blocks a single definition is limited to.

davidcelis avatar Nov 07 '23 19:11 davidcelis