codywb / slack-pyblock-builder

A lightweight Python library with a declarative syntax for simplifying building apps using Slack's Block Kit UI framework
BSD 3-Clause "New" or "Revised" License
6 stars 0 forks source link

logo-full

PyBlock Builder is a lightweight library written in Python for constructing UI with Slack's Block Kit UI framework. It was designed to make it easier for anyone—from hobbyists to professional devs—to create Slack apps faster with fewer lines of code.

For the purposes of demonstrating how to use the features of PyBlock Builder, this documentation assumes at least basic familiarity with the Slack platform, the Slack API, the Block Kit UI framework, and the Bolt for Python SDK. If you are new to any or all of these, please check out the great documentation provided by Slack from the link above.


img img

💡 Features

🎯Benefits


🔰 Getting Started

Installation

Using pip:

pip install pyblock-builder
*Note that macOS/Linux users may need to use pip3 instead of pip depending on your individual environment settings.

Usage

PyBlock Builder is made up of the following components:

surfaces - A collection of classes representing app surfaces on the Slack platform, such as Message and AppHome.

blocks - A collection of classes representing blocks—visual components that can be arranged to create app layouts—from Slack's Block Kit UI framework. These can be added to your app's surfaces and include Section and Input.

elements - A collection of classes representing block elements—the UI elements such as Button and SelectMenu used to capture user interaction. These can be added to your app's blocks.

objects - A collection of classes representing composition objects—items used to define text, options, or other interactive features within certain blocks and block elements. These include Text, Option, and ConfirmationDialog.

mrkdwn - A collection of functions provided to simplify working with Slack's mrkdwn standard, such as bold() or blockquote().

Compatibility

The current version of PyBlock Builder features support for the following parts of the Slack API and Block Kit framework:

Supported? Corresponding PyBlock Builder Class
App Surfaces
└ App Home :white_check_mark: surfaces.app_home.AppHome()
└ Modal :white_check_mark: surfaces.modal.Modal()
└ Message :white_check_mark: surfaces.message.Message()
└ Workflow Step :x:
Blocks
└ Actions :white_check_mark: blocks.actions.Actions()
└ Context :white_check_mark: blocks.context.Context()
└ Divider :white_check_mark: blocks.divider.Divider()
└ File :white_check_mark: blocks.file.File()
└ Header :white_check_mark: blocks.headaer.Header()
└ Image :white_check_mark: blocks.image.Image()
└ Input :white_check_mark: blocks.input.Input()
└ Rich Text :x:
└ Section :white_check_mark: blocks.section.Section()
└ Video :white_check_mark: blocks.video.Video()
Block Elements
└ Button :white_check_mark: elements.button.Button()
└ Checkboxes :white_check_mark: elements.checkboxes.Checkboxes()
└ Date Picker :white_check_mark: elements.date_picker.DatePicker()
└ Datetime Picker :white_check_mark: elements.datetime_picker.DatetimePicker()
└ Email Input :white_check_mark: elements.email_input.EmailInput()
└ Image :white_check_mark: elements.image.ImageElement()
└ Multi-select Menu :white_check_mark: elements.multiselect_menu.MultiStaticSelect()
elements.multiselect_menu.MultiUsersSelect()
elements.multiselect_menu.MultiConversationsSelect()
elements.multiselect_menu.MultiChannelsSelect()
└ Number Input :white_check_mark: elements.number_input.NumberInput()
└ Overflow Menu :white_check_mark: elements.overflow_menu.OverflowMenu()
└ Plain-text Input :white_check_mark: elements.plain_text_input.PlainTextInput()
└ Radio Buttons :white_check_mark: elements.radio_buttons.RadioButtons()
└ Select Menu :white_check_mark: elements.select_menu.StaticSelectMenu()
elements.select_menu.UsersSelectMenu()
elements.select_menu.ConversationsSelectMenu()
elements.select_menu.ChannelsSelectMenu()
└ Time Picker :white_check_mark: elements.time_picker.TimePicker()
└ URL Input :white_check_mark: elements.url_input.UrlInput()
└ Workflow Button :x:
Composition Objects
└ Confirmation Dialog :white_check_mark: objects.confirmation_dialog.ConfirmationDialog()
└ Conversations Filter :white_check_mark: objects.conversations_filter.ConversationsFilter()
└ Dispatch Action Configuration :white_check_mark: objects.dispatch_action_configuration.DispatchActionConfig()
└ Option :white_check_mark: objects.option.Option()
└ Options Group :white_check_mark: objects.options_group.OptionsGroup()
└ Text :white_check_mark: objects.text.Text()
└ Trigger :x:
└ Workflow Object :x:

Importing

The best practice for surfaces, blocks, elements, and objects is to import only the components required using absolute imports.

For example, a simple chatbot app may begin with something like this:

from pyblock_builder.surfaces import Message
from pyblock_builder.blocks import Section, Actions
from pyblock_builder.elements import Button

For PyBlock Builder's mrkdwn helper functions, the best practice is to import the module using the alias md to avoid any potential conflict or confusion with similarly named functions or variables.

# Allow for formatting using syntax such as md.bold(), md.emoji(), etc.
from pyblock_builder import mrkdwn as md

However, if this is not to your liking and you are confident that no such conflicts or confusion will arise, you may alternatively import the module in such a way as to enable access to each helper function directly:

# Enable bold(), blockquote(), inline_code(), and link() to be called directly. 
# Recommended when you know you will only need a few specific funtions
from pyblock_builder.mrkdwn import bold, blockquote, inline_code, link

# Enable all functions in the module to be called directly
from pyblock_builder.mrkdwn import *

Working with Messages

Messages are the core of the Slack platform and PyBlock Builder is optimized for use with Slack's Bolt for Python SDK to make working with them as efficient and painless as possible.

The App Home surface is a place where users can enjoy alone time with your app. Like with messages, PyBlock Builder is optimized for use with Slack's Bolt for Python SDK to make publishing views to and updating views on App Home tabs a piece of cake.

Working with Modals

Modals are focused surfaces that allow you to collect user data and display dynamic information. Like with messages and Home tab views, PyBlock Builder is optimized for use with Slack's Bolt for Python SDK to make working with Modal views as simple as can be.