or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

app-configuration.mdcontext-and-utilities.mdevent-listeners.mdframework-integration.mdindex.mdoauth-and-installation.md
tile.json

tessl/pypi-slack-bolt

The Bolt Framework for Python - a comprehensive framework for building Slack applications with decorator-based API for handling events, actions, and interactive components

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/slack-bolt@1.24.x

To install, run

npx @tessl/cli install tessl/pypi-slack-bolt@1.24.0

index.mddocs/

Slack Bolt Python Framework

The Bolt Framework for Python is a comprehensive library for building Slack applications with modern, decorator-based APIs. It provides developers with tools for handling Slack events, actions, shortcuts, slash commands, and interactive components, supporting both synchronous and asynchronous programming models.

Package Information

  • Package Name: slack-bolt
  • Language: Python
  • Installation: pip install slack-bolt
  • Repository: https://github.com/slackapi/bolt-python
  • Documentation: https://slack.dev/bolt-python/

Core Imports

from slack_bolt import App

For asynchronous applications:

from slack_bolt.async_app import AsyncApp

Import additional utilities as needed:

from slack_bolt import BoltContext, Args
from slack_bolt.oauth.oauth_flow import OAuthFlow
from slack_bolt.oauth.oauth_settings import OAuthSettings
from slack_bolt.middleware.custom_middleware import CustomMiddleware

Basic Usage

Simple Event Listener App

from slack_bolt import App

# Initialize app with bot token and signing secret
app = App(
    token="xoxb-your-bot-token",
    signing_secret="your-signing-secret"
)

# Listen for message events containing "hello"
@app.message("hello")
def say_hello(message, say):
    say(f"Hello <@{message['user']}>!")

# Listen for slash commands
@app.command("/weather")
def weather_command(ack, respond, command):
    ack()  # Always acknowledge commands immediately
    city = command['text'] or "San Francisco"
    respond(f"The weather in {city} is sunny! ☀️")

# Listen for button clicks
@app.action("approve_button")
def handle_approve(ack, respond, body):
    ack()
    user = body["user"]["name"]
    respond(f"<@{user}> approved the request!")

# Start the app
if __name__ == "__main__":
    app.start(port=int(os.environ.get("PORT", 3000)))

Multi-Workspace OAuth App

from slack_bolt import App
from slack_bolt.oauth.oauth_flow import OAuthFlow
from slack_bolt.oauth.oauth_settings import OAuthSettings

# Configure OAuth flow for multi-workspace installation
oauth_settings = OAuthSettings(
    client_id="your-client-id",
    client_secret="your-client-secret",
    scopes=["chat:write", "commands", "app_mentions:read"],
    install_path="/slack/install",
    redirect_uri_path="/slack/oauth_redirect"
)

app = App(
    signing_secret="your-signing-secret",
    oauth_settings=oauth_settings
)

@app.event("app_mention")
def handle_mention(event, say):
    say(f"Thanks for mentioning me, <@{event['user']}>!")

app.start(port=3000)

Architecture

Slack Bolt follows an event-driven architecture with several key components:

  • App/AsyncApp: Main application class that manages listeners, middleware, and request routing
  • Listeners: Decorator-based functions that respond to specific Slack events, commands, or actions
  • Context Objects: Rich objects providing utilities like ack(), say(), respond(), and client for API calls
  • Middleware: Request processing pipeline for authentication, logging, and custom logic
  • Adapters: Integration layers for web frameworks like FastAPI, Flask, Django, and cloud platforms

The framework supports both single-workspace apps (with hardcoded tokens) and multi-workspace apps (with OAuth installation flows), and provides both synchronous and asynchronous programming models.

Capabilities

App Configuration & Setup

Core application setup including single vs multi-workspace configuration, OAuth flows, Socket Mode, and essential middleware options. Covers both App and AsyncApp initialization patterns.

class App:
    def __init__(
        self,
        *,
        logger=None,
        name: str = None,
        process_before_response: bool = False,
        signing_secret: str = None,
        token: str = None,
        client=None,
        authorize=None,
        installation_store=None,
        oauth_settings: OAuthSettings = None,
        oauth_flow: OAuthFlow = None,
        # ... many more configuration options
    ): ...
    
    def start(self, port: int = 3000, path: str = "/slack/events", host: str = "0.0.0.0"): ...

App Configuration & Setup

Event Listeners & Request Handling

Decorator-based event handling for all Slack event types including messages, slash commands, interactive components, shortcuts, and view submissions. Supports event filtering and custom matchers.

def message(self, keyword=None, *matchers): ...
def command(self, command, *matchers): ...
def event(self, event_type, *matchers): ...
def action(self, action_id, *matchers): ...
def shortcut(self, callback_id, *matchers): ...
def view(self, callback_id, *matchers): ...
def options(self, action_id, *matchers): ...

Event Listeners & Request Handling

Context Objects & Utilities

Rich context objects providing utilities for acknowledging requests, sending messages, making API calls, and accessing request data. Includes argument injection system for clean listener functions.

class BoltContext:
    client: WebClient
    ack: Ack
    say: Say
    respond: Respond
    logger: Logger
    # ... additional properties
    
def ack(response=None): ...
def say(text: str = None, **kwargs): ...
def respond(text: str = None, **kwargs): ...

Context Objects & Utilities

OAuth & Multi-Workspace Installation

OAuth 2.0 flow implementation for multi-workspace Slack app installation and management. Includes installation stores, token management, and authorization patterns.

class OAuthFlow:
    def __init__(self, *, settings: OAuthSettings, logger: Logger = None): ...

class OAuthSettings:
    def __init__(
        self,
        *,
        client_id: str,
        client_secret: str,
        scopes: Union[str, Sequence[str]],
        redirect_uri_path: str = "/slack/oauth_redirect",
        install_path: str = "/slack/install"
    ): ...

OAuth & Multi-Workspace Installation

Middleware System

Request processing pipeline with built-in middleware for authentication, request verification, and logging. Supports custom middleware development and per-listener middleware.

def use(self, *middleware): ...
def middleware(self, *middleware): ...
def error(self, error_handler): ...

class CustomMiddleware:
    def __init__(self, app_name: str = None): ...
    def process(self, *, req: BoltRequest, resp: BoltResponse, next): ...

App Configuration & Setup

Interactive UI Components

Handling of Slack's interactive UI components including Block Kit elements, modal views, shortcuts, and form submissions. Covers view management and complex UI workflows.

def view_submission(self, callback_id, *matchers): ...
def view_closed(self, callback_id, *matchers): ...
def block_action(self, action_id, *matchers): ...
def global_shortcut(self, callback_id, *matchers): ...
def message_shortcut(self, callback_id, *matchers): ...

Event Listeners & Request Handling

Web Framework Integration

Adapters for integrating Bolt apps with popular Python web frameworks and deployment platforms. Supports FastAPI, Flask, Django, ASGI/WSGI, and cloud platforms.

# FastAPI example
from slack_bolt.adapter.fastapi import SlackRequestHandler
handler = SlackRequestHandler(app)
fastapi_app.post("/slack/events")(handler.handle)

# Flask example  
from slack_bolt.adapter.flask import SlackRequestHandler
handler = SlackRequestHandler(app)
flask_app.route("/slack/events", methods=["POST"])(handler.handle)

Web Framework Integration

AI Agents & Assistant Features

AI assistant middleware for building conversational AI experiences within Slack. Includes thread context management, assistant-specific utilities, and workflow integration.

from slack_bolt.middleware.assistant import Assistant

class Assistant:
    def __init__(self, thread_context_store=None): ...

def set_status(text: str): ...
def set_title(title: str): ...
def set_suggested_prompts(prompts: List[str]): ...
def save_thread_context(context: dict): ...

Context Objects & Utilities

Asynchronous Programming

AsyncApp for high-performance asynchronous Slack applications. Includes async decorators, utilities, and integration patterns for async web frameworks.

class AsyncApp:
    def __init__(self, **kwargs): ...
    
    async def start_async(self, port: int = 3000): ...
    
    def message(self, keyword=None, *matchers): ...  # Returns async decorator
    def command(self, command, *matchers): ...       # Returns async decorator

App Configuration & Setup

Error Handling

class BoltError(Exception): ...

class BoltUnhandledRequestError(BoltError):
    request: BoltRequest
    body: dict
    current_response: BoltResponse
    last_global_middleware_name: str

Common error patterns and debugging techniques are covered in the middleware and context documentation.

Version Information

__version__ = "1.24.0"