A python3 wrapper for the slack block kit framework
Project description
Slack Blocks Wrapper
Slack blocks wrapper is a python3 wrapper around the slack blocks framework. It provides a simple way to create and send blocks to slack.
Installation
pip install slack-blocks-wrapper
Slack blocks wrapper has no dependencies outside python3. Currently, it is only supported and tested on python3.9.
Usage
You can use the wrapper to create blocks in a few different ways.
Here's an example of a section with a multi-static select menu:
from slack_blocks_wrapper import section
multistatic_select_node = section.multistatic_select_element(
placeholder="Select a color",
action_id="color_select",
options=[
section.text_node(
text="Red",
text_type=section.TextType.PLAIN_TEXT,
value="red"
),
section.text_node(
text="Green",
text_type=section.TextType.PLAIN_TEXT,
value="green"
),
section.text_node(
text="Blue",
text_type=section.TextType.PLAIN_TEXT,
value="blue"
)
]
)
You can use this element with the Bolt framework to create a multi-static select menu as follows:
import logging
import os
from flask import Flask
from slack_bolt import App
from slack_bolt.adapter.flask import SlackRequestHandler
from slack_blocks_wrapper import section
block_element = section.multistatic_select_element(
placeholder="Select a color",
action_id="color_select",
options=[
section.text_node(
text="Red",
text_type=section.TextType.PLAIN_TEXT,
value="red"
),
section.text_node(
text="Green",
text_type=section.TextType.PLAIN_TEXT,
value="green"
),
section.text_node(
text="Blue",
text_type=section.TextType.PLAIN_TEXT,
value="blue"
)
]
)
app = Flask(__name__)
handler = SlackRequestHandler(bolt_app)
logging.basicConfig(level=logging.DEBUG)
bolt_app = App()
@bolt_app.command("/hello-world")
def hello(ack):
ack(blocks=[block_element])
@app.route("/slack/events", methods=["POST"])
def slack_events():
return handler.handle(request)
# Only for local debug
if __name__ == "__main__":
app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 3000)))
Thus far, the following block kit builder elements are supported:
- Section - All section elements are supported.
- Actions - All action elements are supported.
- Context - All context elements are supported.
- Divider - All divider elements are supported.
- Image - All image elements are supported.
- Input - All input elements are supported.
- Header - All header elements are supported.
- Divider - All divider elements are supported.
Better documentation and implementation improvements are coming soon.
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
Built Distribution
Hashes for slack-blocks-wrapper-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa785d2af4c9f36d318b99c58e15f8cdc2a61c36f0c3ce81949a823afb7aa504 |
|
MD5 | c6eb9b6cb613a8e47e2af1116c26bc38 |
|
BLAKE2b-256 | 85562577a8218bdc15b1954a99f7babb47881137f3e9b57acf5c0271dbef8978 |
Hashes for slack_blocks_wrapper-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff6109da9daa0aaf6f0343649a735a7e367b441a42e36d36becd4be552f22ba4 |
|
MD5 | 50677ca211dc3938d7902f86013ad31d |
|
BLAKE2b-256 | d60082c5a8d0d29eb9c8117b68ae74810a2f8705489af69953396cd31ab62326 |