A Python framework to build Slack apps in a flash with the latest platform features. Read the getting started guide and look at our code examples to learn how to build apps using Bolt. The Python module documents are available here.
# Python 3.7+ required
python -m venv .venv
source .venv/bin/activate
pip install -U pip
pip install slack_boltCreate a Bolt for Python app by calling a constructor, which is a top-level export. If you'd prefer, you can create an async app.
import logging
logging.basicConfig(level=logging.DEBUG)
from slack_bolt import App
# export SLACK_SIGNING_SECRET=***
# export SLACK_BOT_TOKEN=xoxb-***
app = App()
# Add functionality here
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 use Socket Mode for running your app, SocketModeHandler is available for it.
import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler
# Install the Slack app and get xoxb- token in advance
app = App(token=os.environ["SLACK_BOT_TOKEN"])
# Add functionality here
if __name__ == "__main__":
# Create an app-level token with connections:write scope
handler = SocketModeHandler(app, os.environ["SLACK_APP_TOKEN"])
handler.start()Run the app this way:
export SLACK_APP_TOKEN=xapp-***
export SLACK_BOT_TOKEN=xoxb-***
python app.py
# SLACK_SIGNING_SECRET is not required
# Running ngrok is not requiredApps typically react to a collection of incoming events, which can correspond to Events API events, actions, shortcuts, slash commands or options requests. For each type of request, there's a method to build a listener function.
# Listen for an action from a Block Kit element (buttons, select menus, date pickers, etc)
app.action(action_id)(fn)
# Listen for dialog submissions
app.action({"callback_id": callbackId})(fn)
# Listen for slash commands
app.command(command_name)(fn)
# Listen for an event from the Events API
app.event(event_type)(fn)
# Listen for a custom step execution from a workflow
app.function(callback_id)(fn)
# Convenience method to listen to only `message` events using a string or re.Pattern
app.message([pattern ,])(fn)
# Listen for options requests (from select menus with an external data source)
app.options(action_id)(fn)
# Listen for a global or message shortcuts
app.shortcut(callback_id)(fn)
# Listen for view_submission modal events
app.view(