Skip to main content

No project description provided

Project description

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:

from blockkit import Message, blocks, elements, objects

message = 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:

from blockkit import elements


value = elements.Button.parse_value(action_payload["actions"][0])

Basic view submission payload parsing:

Define the view:

from blockkit import blocks, views, objects


modal = 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:

from blockkit import blocks


value = 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:

from blockkit import blocks, views, objects
from blockkit.fixed_blocks import FixedPlainTextInput


class 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:

value = UsernameInput.parse(view_payload)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

slacktools-blockkit-0.11.0.tar.gz (22.3 kB view hashes)

Uploaded Source

Built Distribution

slacktools_blockkit-0.11.0-py3-none-any.whl (34.3 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page