Giter VIP home page Giter VIP logo

Comments (13)

simonh1000 avatar simonh1000 commented on June 9, 2024 15

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

from slack-api-specs.

x3ro avatar x3ro commented on June 9, 2024 4

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 😕

from slack-api-specs.

lawrencegripper avatar lawrencegripper commented on June 9, 2024 4

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 🥳

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"
        }
      },

from slack-api-specs.

riffraff avatar riffraff commented on June 9, 2024 3

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.

from slack-api-specs.

fab-mindflow avatar fab-mindflow commented on June 9, 2024 1

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

Would it be possible to share this JSON schema officially?

from slack-api-specs.

delanni avatar delanni commented on June 9, 2024 1

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.

from slack-api-specs.

lawrencegripper avatar lawrencegripper commented on June 9, 2024 1

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

from slack-api-specs.

episod avatar episod commented on June 9, 2024

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.

from slack-api-specs.

fab-mindflow avatar fab-mindflow commented on June 9, 2024

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

from slack-api-specs.

fab-mindflow avatar fab-mindflow commented on June 9, 2024

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

from slack-api-specs.

lawrencegripper avatar lawrencegripper commented on June 9, 2024

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 🙏

from slack-api-specs.

okeeffed avatar okeeffed commented on June 9, 2024

Stoked that it managed to help out @lawrencegripper ❤️

from slack-api-specs.

davidcelis avatar davidcelis commented on June 9, 2024

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.

from slack-api-specs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.