feat(block-kit): add block element examples - #227
Conversation
156b8aa to
e41731b
Compare
Add examples for the block elements that the SDK already implements, each in its own file under block-kit/src/block_elements/ with a matching test. Every example mirrors the JSON payload(s) from the element's docs.slack.dev reference page verbatim -- hosted in a valid block (or input) where the element requires one -- so each is a runnable payload rather than a bare element that cannot be sent on its own. Where a reference page documents several payloads, every one is exemplified (for instance the select and multi-select menus each cover all five source variants, and the image element covers image_url and both slack_file forms). Tests assert the complete reference JSON. Covered: button, checkboxes, date picker, datetime picker, email input, file input, image, multi-select menu, number input, overflow menu, plain-text input, radio button group, select menu, time picker, URL input, and workflow button. Descriptions match the docs copy verbatim, following the existing blocks/ convention. The button page also documents an agent_prompt variant (Slackbot hand-off) that the SDK does not yet implement -- deferred here. This PR is the home for block elements the SDK implements; elements not yet implemented in the SDK are a separate follow-up. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
e41731b to
099fd69
Compare
Adds examples for documented block elements the palette was missing: the rich-text sub-elements (emoji, broadcast, color, date, link, text, channel, user, usergroup, team), the rich-text containers (section, list, quote, preformatted), the rich-text input, the context_actions elements (feedback buttons, icon button), and the URL source. Each ships a matching test asserting the complete reference JSON from docs.slack.dev, plus an alphabetical README entry. Also reformats every existing block_elements test's expected payload to one key per line with a magic trailing comma so ruff format keeps them exploded. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Renames src/block_elements/ -> src/elements/ (and the mirrored tests/) so the example layout reads blocks/ + elements/, matching the docs.slack.dev path structure (Blocks and Block elements are siblings under Block Kit). Import paths and README implementation links follow; the docs URL slug (block-elements, hyphenated) is unchanged, and the SDK's own slack_sdk.models.blocks.block_elements imports are untouched.
…le05 Match the bolt-js-examples numbering: the section+actions button payload is example05 in both, leaving example04 reserved for the deferred agent_prompt button variant (unimplementable against slack_sdk 3.44.0). Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
The checkboxes example returned a bare SectionBlock, dropping the modal view the docs example wraps it in. Rebuild example01 to return the complete View (type: modal, title/submit/close, blocks) so it matches the docs checkboxes-element payload field-for-field, and assert the full view in the test. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
… docs view The docs.slack.dev reference pages show these two elements inside a full view, not as a bare input block: - file_input → a modal view (type/title/submit/close + blocks) - rich_text_input → a home view (type: "home" + blocks) Return the full View from example01() in each so the built payload matches the docs sample JSON 1:1 (same view-wrapper class as the checkboxes fix), and assert the complete view in each test. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
The per-example docstring line (the descriptive line after the docs one-liner) should match the wording reviewed in the JS examples, which are the source of truth for these descriptions (slack-samples/bolt-js-examples#215). Conform every Python element example's descriptive line to its JS counterpart verbatim; the first docstring line (which tracks the docs.slack.dev reference one-liner) and all payloads are unchanged. checkboxes and workflow_button have no JS example, so their descriptions are left as-is. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Use the concise "A section block containing a group of checkboxes." descriptive line, matching the reviewed wording style. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Drop the explicit emoji=None on plain_text objects whose docs.slack.dev reference example omits the emoji field (feedback buttons, icon button, rich text input placeholder). slack_sdk drops None fields, so the serialized payload is unchanged — this only removes redundant source. emoji=True is kept where the docs example shows "emoji": true. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Build rich text styling with RichTextElementParts.TextStyle(bold=...,
italic=..., strike=...) instead of a stringly-typed style={"bold": True}
dict, in the rich_text_section and text examples. TextStyle serializes
identically, so the payload is unchanged, but the examples now model the
idiomatic, type-checked way to style rich text with the SDK.
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…rding
Match the element-purpose first line to the reviewed JS wording
("Displays a URL source for referencing within a task card block.") so
the two example sets read the same for this element.
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…ding Align the element-purpose first line to the reviewed JS example so the two sets read identically. NB: the docs time-picker `summary:` frontmatter is a known upstream bug (it carries the number-input text); JS mirrors it and Python now matches. Both will be re-aligned to the corrected wording once the docs summary fix lands (tracked in the devspace-dotfiles queue). Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
…ary) The time-picker-element docs description: frontmatter carries the number-input text upstream (docs repo content/reference/block-kit/ block-elements/time-picker-element.md:2). JS mirrors it verbatim; this aligns the Python README implementation-list line the same way so the docstring, README, and JS all move in lockstep when the upstream docs fix lands. Traceability probe — do not pre-correct. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
zimeg
left a comment
There was a problem hiding this comment.
🐍 Notes on more review after comparing to adjacent slack-samples/bolt-js-examples#215!
| ) | ||
|
|
||
|
|
||
| def example01() -> list[RichTextBlock]: |
There was a problem hiding this comment.
📝 note: This pattern exists just for these returns but matches current implementation of this example:
bolt-python-examples/block-kit/src/blocks/rich_text.py
Lines 11 to 69 in ab9308d
| customizable_input_parameters=[ | ||
| { | ||
| "name": "input_parameter_a", | ||
| "value": "Value for input param A", | ||
| }, | ||
| { | ||
| "name": "input_parameter_b", | ||
| "value": "Value for input param B", | ||
| }, | ||
| ], |
There was a problem hiding this comment.
🌲 note: These parameters within the workflow_button trigger don't have classes available so for now the example uses plain objects.
There was a problem hiding this comment.
☕ note: Example implementation shows a structure here has precedence!
| - **[Select menu](https://docs.slack.dev/reference/block-kit/block-elements/select-menu-element)**: Allows users to choose an option from a drop down menu. [Implementation](./src/elements/select_menu.py). | ||
| - **[Team](https://docs.slack.dev/reference/block-kit/block-elements/team-element)**: Renders as a mention of a workspace or team. [Implementation](./src/elements/team.py). | ||
| - **[Text](https://docs.slack.dev/reference/block-kit/block-elements/text-element)**: Displays text, optionally with styling. [Implementation](./src/elements/text.py). | ||
| - **[Time picker](https://docs.slack.dev/reference/block-kit/block-elements/time-picker-element)**: Allows users to enter numerical data into a single-line field. [Implementation](./src/elements/time_picker.py). |
There was a problem hiding this comment.
⌛ note: This is perhaps unexpected working upstream according to some metadata but we're matching what's shown in HTML at this time.
The docs.slack.dev workflow-button-element page describes this example as "a section block containing a workflow button element" — match that prose (was "a section block with a workflow button as an accessory") and keep it identical to bolt-java-examples. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
|
🚢 Merging after match with slack-samples/bolt-java-examples#69 and slack-samples/bolt-js-examples#215! |
Summary
Adds dedicated block element examples under
block-kit/, one file per element insrc/elements/with a matching test intests/elements/.Each example mirrors the JSON payload(s) from the element's docs.slack.dev reference page verbatim — hosted in a valid block (or input) where the element requires one, so each is a runnable payload rather than a bare element that can't be sent on its own. Where a reference page documents multiple payloads, every one is exemplified, and each test asserts the complete reference JSON.
The example directory is
elements/(notblock_elements/) so the layout readsblocks/+elements/, matching the docs.slack.dev path structure where Blocks and Block elements are siblings under Block Kit — and matching the sibling bolt-js-examples and bolt-java-examples PRs. The SDK's ownslack_sdk.models.blocks.block_elementsimports are unaffected by the rename.This PR is the home for block elements the SDK implements; elements not yet implemented in the SDK are a separate follow-up.
Elements covered
34 elements, 49 examples.
image_url,slack_fileby url,slack_fileby id)Deferred
The button reference page also documents an
agent_promptvariant (Slackbot hand-off), which the SDK does not yet implement — deferred here rather than shipping an example whose serialized payload wouldn't include the field.Testing
ruff check,ruff format --check,mypy, andpytestall pass inblock-kit/(83 tests).