Skip to main content

The Bolt Framework for Python

Project description

⚠️ Important Notice ⚠️

🔄 Still Work In Progress 🔄

This project is still in alpha, and may have bugs in it. Also, the public APIs can be changed until the v1 release. We are keen to hear your feedback. Please feel free to submit an issue!

Bolt for Python (still in alpha)

Python Version pypi package Build Status Codecov

A Python framework to build Slack apps in a flash with the latest platform features. Check the samples to know how to use this framework.

Setup

python -m venv env
source env/bin/activate
pip install slack_bolt

First Bolt App (app.py)

Create an app by calling a constructor, which is a top-level export.

import logging
logging.basicConfig(level=logging.DEBUG)

from slack_bolt import App

# export SLACK_SIGNING_SECRET=***
# export SLACK_BOT_TOKEN=xoxb-***
app = App()

# Middleware
@app.middleware  # or app.use(log_request)
def log_request(logger, body, next):
    logger.info(body)
    return next()

# Events API: https://api.slack.com/events-api
@app.event("app_mention")
def event_test(say):
    say("What's up?")

# Interactivity: https://api.slack.com/interactivity
@app.shortcut("callback-id-here")
# @app.command("/hello-bolt-python")
def open_modal(ack, client, logger, body):
    # acknowledge the incoming request from Slack immediately
    ack()
    # open a modal
    api_response = client.views_open(
        trigger_id=body["trigger_id"],
        view={
            "type": "modal",
            "callback_id": "view-id",
            "title": {
                "type": "plain_text",
                "text": "My App",
            },
            "submit": {
                "type": "plain_text",
                "text": "Submit",
            },
            "blocks": [
                {
                    "type": "input",
                    "block_id": "b",
                    "element": {
                        "type": "plain_text_input",
                        "action_id": "a"
                    },
                    "label": {
                        "type": "plain_text",
                        "text": "Label",
                    }
                }
            ]
        })
    logger.debug(api_response)

@app.view("view-id")
def view_submission(ack, body, logger):
    ack()
    # Prints {'b': {'a': {'type': 'plain_text_input', 'value': 'Your Input'}}}
    logger.info(body["view"]["state"]["values"])

if __name__ == "__main__":
    app.start(3000)  # POST http://localhost:3000/slack/events

Run the Bolt App

export SLACK_SIGNING_SECRET=***
export SLACK_BOT_TOKEN=xoxb-***
python app.py

# in another terminal
ngrok http 3000

Feedback

We are keen to hear your feedback. Please feel free to submit an issue!

License

The MIT License

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

slack_bolt-0.5.0a0.tar.gz (48.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

slack_bolt-0.5.0a0-py2.py3-none-any.whl (96.6 kB view details)

Uploaded Python 2Python 3

File details

Details for the file slack_bolt-0.5.0a0.tar.gz.

File metadata

  • Download URL: slack_bolt-0.5.0a0.tar.gz
  • Upload date:
  • Size: 48.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for slack_bolt-0.5.0a0.tar.gz
Algorithm Hash digest
SHA256 9f4176d4759927f278f48b575aafd8eccdae2f2e0b3a7787ca8c781b85e242ef
MD5 ce07e2017f1ebf94a2cb026d701ddb94
BLAKE2b-256 3313560c2123cdc281edea0a1d6ee27fded9d9a6ce22178c912d19f992b34f3a

See more details on using hashes here.

File details

Details for the file slack_bolt-0.5.0a0-py2.py3-none-any.whl.

File metadata

  • Download URL: slack_bolt-0.5.0a0-py2.py3-none-any.whl
  • Upload date:
  • Size: 96.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for slack_bolt-0.5.0a0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 57a07dcf002188facf6f65e597be91697f5018893cb68c0d4868c9afe195954b
MD5 d07d2797af6fc58994e074dba3a70c82
BLAKE2b-256 b0f0c7042b76946e22423a1ab640419aae80f2265a918c90e87c9cc420c6b264

See more details on using hashes here.

Supported by

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