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)
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, payload, next):
logger.info(payload)
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, payload):
# acknowledge the incoming request from Slack immediately
ack()
# open a modal
api_response = client.views_open(
trigger_id=payload["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, payload, logger):
ack()
# Prints {'b': {'a': {'type': 'plain_text_input', 'value': 'Your Input'}}}
logger.info(payload["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.2.1a0.tar.gz
(36.0 kB
view hashes)
Built Distribution
Close
Hashes for slack_bolt-0.2.1a0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cde1b792ab57cdb10e3dd38efe22acf90e0da81a34166bbfcd0c94953c176260 |
|
MD5 | 570b79ed991c3648c3002e245e1a87e2 |
|
BLAKE2b-256 | 8845419bd082d43c68bb7f7a2e7b46fcb57772d81e42537038942211eedf895a |