Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/danpoland/slacktools-blockkit
Python toolkit for building Slack UIs using the block-kit framework
https://github.com/danpoland/slacktools-blockkit
Last synced: 3 months ago
JSON representation
Python toolkit for building Slack UIs using the block-kit framework
- Host: GitHub
- URL: https://github.com/danpoland/slacktools-blockkit
- Owner: danpoland
- License: mit
- Created: 2020-02-18T20:01:38.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-02-10T22:46:31.000Z (almost 2 years ago)
- Last Synced: 2024-06-28T05:37:44.652Z (5 months ago)
- Language: Python
- Homepage:
- Size: 127 KB
- Stars: 5
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# slacktools-blockkit
slacktools-blockkit provides an expressive interface for utilizing the Slack Block-kit UI framework.
#### Features:
* Build Slack UIs by composing classes instead of manually constructing dictionaries.
* Easily parse action payloads and modal submission payloads without manual dictionary traversal.
* Compose your own reusable blocks with fixed attributes and avoid magic string lookups when parsing interactive payloads.#### Installation:
`pip install slacktools-blockkit`#### Basic Usage:
```python
from blockkit import Message, blocks, elements, objectsmessage = Message(blocks=[
blocks.Section(objects.MrkdwnText("*User Information: ")),
blocks.Divider(),
blocks.Section(
objects.PlainText("John Doe"),
fields=[
objects.MrkdwnText("Address:\n"),
objects.PlainText("123 Street, City, 11111"),
objects.MrkdwnText("Phone: \n"),
objects.PlainText("111-111-1111")
]
),
blocks.Actions(elements=[
elements.Button(
action_id="delete",
text="Delete User",
style=elements.Button.Styles.DANGER
)
])
])
```Parsing action payloads:
```python
from blockkit import elementsvalue = elements.Button.parse_value(action_payload["actions"][0])
```
#### Basic view submission payload parsing:
Define the view:
```python
from blockkit import blocks, views, objectsmodal = views.Modal(
title="User Data",
blocks=[
blocks.Section(objects.PlainText("Enter user information:")),
blocks.PlainTextInput(label="Username", block_id="user_data", action_id="username")
]
)
```
Parse the response:
```python
from blockkit import blocksvalue = blocks.PlainTextInput.parse(
view_payload,
block_id="user_data",
action_id="username"
)
```### Fixed blocks and view submission payload parsing:
Define the fixed block and view:
```python
from blockkit import blocks, views, objects
from blockkit.fixed_blocks import FixedPlainTextInputclass UsernameInput(FixedPlainTextInput):
block_id = "user_data"
action_id = "username"
label = "Username"modal = views.Modal(
title="User Data",
blocks=[
blocks.Section(objects.PlainText("Enter user information:")),
UsernameInput()
]
)
```
Parse the response:
```python
value = UsernameInput.parse(view_payload)
```