Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Block Kit header and button accessory #116

Merged
merged 5 commits into from Dec 5, 2022

Conversation

ctypeh
Copy link
Contributor

@ctypeh ctypeh commented Dec 2, 2022

Context

In order to create a more complex slack message, I needed to add support for the Block Kit Header element, and add optional Accessories to Section elements. Headers are a short but high-level, large, bold plaintext element. Accessories allow Block Elements to float to the right of a Section block, to provide small buttons and images close to the section they are related to. Accessories provide a better usage of horizontal space in messages, and prevent using another vertical block row for an element where unnecessary.

Documentation

Relevant Slack API Links

Header Blocks
Section Blocks

Field Type Required? Description
accessory Object No One of the available element objects.

List of Block Elements, also called Element Objects, e.g. buttons

Block elements can be used inside of section, context, input and actions layout blocks.

Code Feature Changes

  • Header blocks are implemented as a core SlackBlock type, accepting one SlackPlainTextOnly element, with a comment noting a maxlength of 150, which is done similarly to other implemented types.
  • Section blocks now also take a Maybe SlackAccessory, to allow the option of tagging one on to the right of a section of text.
  • Slack accessories were added as a new datatype, which can only be a SlackButtonAccessory, which takes a SlackAction (button).
    • Currently, accessories only provide support for buttons. Buttons are defined consistently by the API for use in both action lists (as already implemented,) and in the context of sections as an accessory, so no changes were necessary to them themselves.
    • Support for using images as accessories to sections should be simple enough to implement as well, given the existing implementation of SlackBlockImage which provides the fully-implemented type SlackImage, but was not within my scope of work at this time.
    • For the scope of my work, Slack is not currently desired to write any data out from messages for security/compliance concerns. Since the majority of block elements are interactive in some way that would write from Slack through the API, support for them is not provided at this time.

Effects

  • Breaking Change! Any uses of the type SlackBlockSection provided by this repo will now need to update their code to reflect the addition of the Maybe SlackAccessory which was not previously defined. Providing a simple Nothing after the SlackText provided to the data constructor is sufficient. Given that this code is marked Experimental and development is ongoing, changes like this should not be too surprising.
  • This repo does not provide coded nor documentation of tests for Block Kit elements.

ctypeh and others added 3 commits December 1, 2022 18:13
pairing session with goose to add Header block and support in section blocks for button accessories that float right

Co-Authored-By: Matthew Mongeau <halogenandtoast@gmail.com>
fixed a compilation error in the buttonAccessory helper builder function
added a show instance for SlackAccessory
leverage the show instance for SlackAccessory to provide a proper show instance for block section with accessory
@ctypeh
Copy link
Contributor Author

ctypeh commented Dec 2, 2022

Details of how immediately this PR would affect MWB if it were merged, and how to mitigate any problems would be appreciated. :)

@ctypeh ctypeh requested a review from lf- December 2, 2022 20:04
@lf-
Copy link
Contributor

lf- commented Dec 2, 2022

I can show you how to write up a golden test to check the JSON output which we can then stick into the block kit builder :)

@lf- lf- force-pushed the violet/expanded-block-kit-support branch from 25c34b3 to 947ff82 Compare December 3, 2022 00:36
Copy link
Contributor

@lf- lf- left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@lf- lf- marked this pull request as ready for review December 3, 2022 00:38
@lf- lf- force-pushed the violet/expanded-block-kit-support branch from 947ff82 to 487090d Compare December 3, 2022 00:41
Co-authored-by: Violet <violet@mercury.com>
@lf- lf- force-pushed the violet/expanded-block-kit-support branch from 487090d to cc07e8d Compare December 3, 2022 00:47
@ctypeh ctypeh merged commit 1ce6045 into master Dec 5, 2022
@ctypeh ctypeh deleted the violet/expanded-block-kit-support branch December 5, 2022 18:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants