A Python framework to build Slack apps in a flash with the latest platform features. Check the document and examples to know how to use this framework.
# Python 3.6+ required python -m venv .venv source .venv/bin/activate pip install -U pip pip install slack_boltCreate an app by calling a constructor, which is a top-level export.
importlogginglogging.basicConfig(level=logging.DEBUG) fromslack_boltimportApp# export SLACK_SIGNING_SECRET=***# export SLACK_BOT_TOKEN=xoxb-***app=App() # Events API: https://api.slack.com/events-api@app.event("app_mention")defevent_test(say): say("What's up?") # Interactivity: https://api.slack.com/interactivity@app.shortcut("callback-id-here")# @app.command("/hello-bolt-python")defopen_modal(ack, client, logger, body): # acknowledge the incoming request from Slack immediatelyack() # open a modalapi_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")defview_submission(ack, view, logger): ack() # Prints{'b':{'a':{'type': 'plain_text_input', 'value': 'Your Input'}}}logger.info(view["state"]["values"]) if__name__=="__main__": app.start(3000) # POST http://localhost:3000/slack/eventsexport SLACK_SIGNING_SECRET=***export SLACK_BOT_TOKEN=xoxb-*** python app.py # in another terminal ngrok http 3000If you prefer building Slack apps using asyncio, you can go with AsyncApp instead. You can use async/await style for everything in the app. To use AsyncApp, AIOHTTP library is required for asynchronous Slack Web API calls and the default web server.
# Python 3.6+ required python -m venv .venv source .venv/bin/activate pip install -U pip # aiohttp is required pip install slack_bolt aiohttpImport slack_bolt.async_app.AsyncApp instead of slack_bolt.App. All middleware/listeners must be async functions. Inside the functions, all utility methods such as ack, say, and respond requires await keyword.
fromslack_bolt.async_appimportAsyncAppapp=AsyncApp() @app.event("app_mention")asyncdefevent_test(body, say, logger): logger.info(body) awaitsay("What's up?") @app.command("/hello-bolt-python")asyncdefcommand(ack, body, respond): awaitack() awaitrespond(f"Hi <@{body['user_id']}>!") if__name__=="__main__": app.start(3000)Starting the app is exactly the same with the way using slack_bolt.App.
export SLACK_SIGNING_SECRET=***export SLACK_BOT_TOKEN=xoxb-*** python app.py # in another terminal ngrok http 3000If you want to use another async Web framework (e.g., Sanic, FastAPI, Starlette), take a look at the built-in adapters and their examples.
We are keen to hear your feedback. Please feel free to submit an issue!
The MIT License