Skip to main content

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, elements

multistatic_select_node = section.multi_static_select(
    text="Select a color",
    action_id="color_select",
    options=[
        elements.text_element(
            text="Red",
            text_type=elements.TextType.PLAIN_TEXT,
            value="red"
        ),
        elements.text_element(
            text="Green",
            text_type=elements.TextType.PLAIN_TEXT,
            value="green"
        ),
        elements.text_element(
            text="Blue",
            text_type=elements.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, request
from slack_bolt import App

from slack_bolt.adapter.flask import SlackRequestHandler
from slack_blocks_wrapper import section, elements

block_element = section.multi_static_select(
    text="Select a color",
    action_id="color_select",
    options=[
        elements.text_element(
            text="Red",
            text_type=elements.TextType.PLAIN_TEXT,
            value="red"
        ),
        elements.text_element(
            text="Green",
            text_type=section.TextType.PLAIN_TEXT,
            value="green"
        ),
        elements.text_element(
            text="Blue",
            text_type=section.TextType.PLAIN_TEXT,
            value="blue"
        )
    ]
)
app = Flask(__name__)
logging.basicConfig(level=logging.DEBUG)
bolt_app = App()
handler = SlackRequestHandler(bolt_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:

  1. Section - All section elements are supported.
  2. Actions - All action elements are supported.
  3. Context - All context elements are supported.
  4. Divider - All divider elements are supported.
  5. Image - All image elements are supported.
  6. Input - All input elements are supported.
  7. Header - All header elements are supported.
  8. 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

slack-blocks-wrapper-0.2.6.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

slack_blocks_wrapper-0.2.6-py3-none-any.whl (18.8 kB view details)

Uploaded Python 3

File details

Details for the file slack-blocks-wrapper-0.2.6.tar.gz.

File metadata

  • Download URL: slack-blocks-wrapper-0.2.6.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.7

File hashes

Hashes for slack-blocks-wrapper-0.2.6.tar.gz
Algorithm Hash digest
SHA256 c58537027ed2fae2b382f0866e3da163e365ebeed9b989b8a1bc4efde7119520
MD5 3edfa6b007d58c27943c0229d04f8737
BLAKE2b-256 91093193f60b808bf8d24704d0db539bc06582909987dd97729fbd8581df1401

See more details on using hashes here.

File details

Details for the file slack_blocks_wrapper-0.2.6-py3-none-any.whl.

File metadata

File hashes

Hashes for slack_blocks_wrapper-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 2e97ed83e446207ca7e20e6c9de1ced9ebc20b3cfaf675f14a98bd1697e9c703
MD5 6fb335b628ff8fb9f523aa818399b689
BLAKE2b-256 f73b88fa5ae9dfc6a9649f171c32d20b96000e22ede519b358568cac9499f7df

See more details on using hashes here.

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