Slack Bolt for Python

1.28.0 · active · verified Thu Apr 09

Slack Bolt for Python is a framework that makes it easy to build Slack apps using the Slack Platform. It simplifies common patterns like handling events, processing interactive components, and sending messages. The library is actively maintained with frequent releases, typically monthly, and is currently at version 1.28.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a minimal Slack Bolt app that responds to 'hello' messages in a channel. It uses Socket Mode for local development, requiring `SLACK_BOT_TOKEN`, `SLACK_SIGNING_SECRET`, and `SLACK_APP_TOKEN` environment variables. For production deployments, an HTTP adapter like Flask, Django, or AWS Lambda is typically used.

import os
from slack_bolt import App
from slack_bolt.adapter.socket_mode import SocketModeHandler

# Initialize your app with your bot token and signing secret
# Ensure SLACK_BOT_TOKEN, SLACK_SIGNING_SECRET, and SLACK_APP_TOKEN are set in your environment
app = App(
    token=os.environ.get("SLACK_BOT_TOKEN", ""),
    signing_secret=os.environ.get("SLACK_SIGNING_SECRET", "")
)

# Listen for messages containing "hello"
@app.message("hello")
def message_hello(message, say):
    # say() sends a message to the same channel where the event was triggered
    say(f"Hey there <@{message['user']}>!")

# Start your app
# For local development, Socket Mode is often used.
# For production, you'd typically use an HTTP adapter (e.g., Flask, AWS Lambda).
if __name__ == "__main__":
    # SLACK_APP_TOKEN is required for Socket Mode
    SocketModeHandler(app, os.environ.get("SLACK_APP_TOKEN", "")).start()

view raw JSON →