or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

event-adapter.mdevent-handling.mdindex.mdserver-integration.md
tile.json

tessl/pypi-slackeventsapi

Python Slack Events API adapter for Flask that provides event-driven Slack app development

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/slackeventsapi@3.0.x

To install, run

npx @tessl/cli install tessl/pypi-slackeventsapi@3.0.0

index.mddocs/

Slack Events API

Python adapter for receiving and parsing events from Slack's Events API using Flask. This library provides an event-driven approach to building Slack applications by allowing developers to attach functions to event listeners, handling authentication, signature verification, and HTTP request processing automatically.

Package Information

  • Package Name: slackeventsapi
  • Language: Python
  • Installation: pip install slackeventsapi

Core Imports

from slackeventsapi import SlackEventAdapter

For exceptions:

from slackeventsapi.server import SlackEventAdapterException

For version information:

from slackeventsapi.version import __version__

For direct SlackServer access (advanced usage):

from slackeventsapi.server import SlackServer

Basic Usage

import os
from slackeventsapi import SlackEventAdapter

# Create the adapter with your Slack app's signing secret
slack_signing_secret = os.environ["SLACK_SIGNING_SECRET"]
slack_events_adapter = SlackEventAdapter(slack_signing_secret, "/slack/events")

# Listen for "reaction_added" events
@slack_events_adapter.on("reaction_added")
def reaction_added(event_data):
    event = event_data["event"]
    emoji = event["reaction"]
    print(f"Reaction added: {emoji}")

# Listen for error events
@slack_events_adapter.on("error")
def error_handler(err):
    print(f"ERROR: {err}")

# Start the built-in Flask server
slack_events_adapter.start(port=3000)

Architecture

The SlackEventAdapter integrates Flask web server capabilities with PyEE event emitter functionality:

  • SlackEventAdapter: Main class inheriting from BaseEventEmitter, providing the public API for event registration and server management
  • SlackServer: Internal Flask server handling HTTP requests, signature verification, and Slack protocol compliance
  • Event Processing: Automatic parsing of Slack event payloads and emission to registered listeners
  • Security: Built-in HMAC-SHA256 signature verification and timestamp validation to prevent replay attacks

Capabilities

Event Adapter

Core functionality for creating and managing Slack event adapters, including initialization, server binding, and lifecycle management.

class SlackEventAdapter(BaseEventEmitter):
    def __init__(self, signing_secret, endpoint="/slack/events", server=None, **kwargs): ...
    def start(self, host='127.0.0.1', port=None, debug=False, **kwargs): ...
    
    # Public attributes
    signing_secret: str  # The signing secret used for request verification
    server: SlackServer  # The internal SlackServer instance

Event Adapter

Event Handling

Event listener registration and management using PyEE's event emitter pattern for processing various Slack event types.

def on(self, event_type: str, callback: callable): ...
def emit(self, event_type: str, *args): ...

Event Handling

Server Integration

Integration with existing Flask applications and Blueprint-based architectures for incorporating Slack event handling into larger web applications.

class SlackServer(Flask):
    def __init__(self, signing_secret, endpoint, emitter, server): ...
    def bind_route(self, server): ...
    
    # Public attributes (accessible via adapter.server)
    signing_secret: str  # The signing secret for request verification
    emitter: SlackEventAdapter  # The parent event adapter instance
    endpoint: str  # The URL endpoint for receiving events
    package_info: str  # User-agent string with version information

Server Integration

Types

class SlackEventAdapterException(Exception):
    """Base exception for all errors raised by the SlackClient library"""
    def __init__(self, msg=None): ...

Constants

__version__: str = "3.0.3"  # from slackeventsapi.version