-
Notifications
You must be signed in to change notification settings - Fork 856
docs(maintainers): adding block kit types instructions #1861
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e6760c0
agents: adding block kit types instructions
srtaalej 142f748
separate block kit steps into slack_sdk/models
srtaalej 6cdcd5d
Update slack_sdk/models/AGENTS.md
srtaalej 4f6f69e
update agents.md
srtaalej e9a85f5
Merge branch 'main' into update-agents-block-kit
srtaalej File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # AGENTS.md — Block Kit Models | ||
|
|
||
| The `slack_sdk/models/` package provides Python classes for building [Block Kit](https://api.slack.com/block-kit) UI layouts. Each class serializes to/from the JSON payloads that the Slack API expects, with helper methods for parsing nested composition objects. | ||
|
|
||
| ## Adding a New Block Kit Type | ||
|
|
||
| Block Kit models live in `slack_sdk/models/blocks/` across three files: | ||
|
|
||
| | File | Contents | | ||
| | --- | --- | | ||
| | `blocks.py` | Layout blocks (`SectionBlock`, `ActionsBlock`, `HeaderBlock`, etc.) | | ||
| | `block_elements.py` | Interactive elements (`ButtonElement`, `StaticSelectElement`, `DatePickerElement`, etc.) | | ||
| | `basic_components.py` | Composition objects (`TextObject`, `Option`, `ConfirmObject`, etc.) | | ||
|
|
||
| All types are exported from `slack_sdk/models/blocks/__init__.py`. | ||
|
|
||
| ### Base class hierarchy | ||
|
|
||
| ``` | ||
| JsonObject | ||
| ├── Block → layout blocks | ||
| ├── BlockElement → non-interactive elements | ||
| │ └── InteractiveElement → elements with action_id | ||
| │ └── InputInteractiveElement → elements usable inside InputBlock | ||
| ├── TextObject → PlainTextObject, MarkdownTextObject | ||
| ├── Option / OptionGroup | ||
| └── ConfirmObject, etc. | ||
| ``` | ||
|
|
||
| Choose the base class that matches the type you're adding. | ||
|
|
||
| ### Steps | ||
|
|
||
| 1. **Define the class** in the appropriate file. Follow this pattern: | ||
|
|
||
| ```python | ||
| class MyNewBlock(Block): | ||
| type = "my_new_block" | ||
|
|
||
| @property | ||
| def attributes(self) -> Set[str]: | ||
| return super().attributes.union({"text", "optional_field"}) | ||
|
|
||
| def __init__(self, *, text: Union[str, dict, TextObject], optional_field: Optional[str] = None, block_id: Optional[str] = None, **others: dict): | ||
| super().__init__(type=self.type, block_id=block_id) | ||
| show_unknown_key_warning(self, others) | ||
| self.text = TextObject.parse(text, default_type=PlainTextObject.type) | ||
| self.optional_field = optional_field | ||
| ``` | ||
|
|
||
| Key conventions: | ||
| - Set `type` class attribute to the Slack API type string | ||
| - Override `attributes` to return the set of JSON field names for serialization | ||
| - Call `super().__init__()` with `type=self.type` | ||
| - Call `show_unknown_key_warning(self, others)` to log unexpected kwargs | ||
| - Use `TextObject.parse()`, `ConfirmObject.parse()`, and `BlockElement.parse()` for nested composition objects | ||
|
|
||
| 2. **Register for deserialization:** | ||
| - **Elements:** Automatic — `BlockElement.parse()` discovers subclasses at runtime via `__subclasses__()`. No manual step needed. | ||
| - **Blocks:** Manual — add an `elif` clause in `Block.parse()` (in `blocks.py`) mapping the type string to the new class. | ||
|
|
||
| 3. **Export the class** — add it to the imports and `__all__` list in `slack_sdk/models/blocks/__init__.py`. | ||
|
|
||
| 4. **Add tests** in `tests/slack_sdk/models/test_blocks.py`. Cover: | ||
| - Round-trip: `input_dict == MyNewBlock(**input_dict).to_dict()` | ||
|
|
||
| 5. **Validate:** `./scripts/run_validation.sh` | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 suggestion(non-blocking): Including a brief description of this entire package might be useful here. I'm not sure how much context otherwise is known but we can iterate on this as we find useful?