or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# Slack Events API

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: slackeventsapi

7

- **Language**: Python

8

- **Installation**: `pip install slackeventsapi`

9

10

## Core Imports

11

12

```python

13

from slackeventsapi import SlackEventAdapter

14

```

15

16

For exceptions:

17

18

```python

19

from slackeventsapi.server import SlackEventAdapterException

20

```

21

22

For version information:

23

24

```python

25

from slackeventsapi.version import __version__

26

```

27

28

For direct SlackServer access (advanced usage):

29

30

```python

31

from slackeventsapi.server import SlackServer

32

```

33

34

## Basic Usage

35

36

```python

37

import os

38

from slackeventsapi import SlackEventAdapter

39

40

# Create the adapter with your Slack app's signing secret

41

slack_signing_secret = os.environ["SLACK_SIGNING_SECRET"]

42

slack_events_adapter = SlackEventAdapter(slack_signing_secret, "/slack/events")

43

44

# Listen for "reaction_added" events

45

@slack_events_adapter.on("reaction_added")

46

def reaction_added(event_data):

47

event = event_data["event"]

48

emoji = event["reaction"]

49

print(f"Reaction added: {emoji}")

50

51

# Listen for error events

52

@slack_events_adapter.on("error")

53

def error_handler(err):

54

print(f"ERROR: {err}")

55

56

# Start the built-in Flask server

57

slack_events_adapter.start(port=3000)

58

```

59

60

## Architecture

61

62

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

63

64

- **SlackEventAdapter**: Main class inheriting from BaseEventEmitter, providing the public API for event registration and server management

65

- **SlackServer**: Internal Flask server handling HTTP requests, signature verification, and Slack protocol compliance

66

- **Event Processing**: Automatic parsing of Slack event payloads and emission to registered listeners

67

- **Security**: Built-in HMAC-SHA256 signature verification and timestamp validation to prevent replay attacks

68

69

## Capabilities

70

71

### Event Adapter

72

73

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

74

75

```python { .api }

76

class SlackEventAdapter(BaseEventEmitter):

77

def __init__(self, signing_secret, endpoint="/slack/events", server=None, **kwargs): ...

78

def start(self, host='127.0.0.1', port=None, debug=False, **kwargs): ...

79

80

# Public attributes

81

signing_secret: str # The signing secret used for request verification

82

server: SlackServer # The internal SlackServer instance

83

```

84

85

[Event Adapter](./event-adapter.md)

86

87

### Event Handling

88

89

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

90

91

```python { .api }

92

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

93

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

94

```

95

96

[Event Handling](./event-handling.md)

97

98

### Server Integration

99

100

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

101

102

```python { .api }

103

class SlackServer(Flask):

104

def __init__(self, signing_secret, endpoint, emitter, server): ...

105

def bind_route(self, server): ...

106

107

# Public attributes (accessible via adapter.server)

108

signing_secret: str # The signing secret for request verification

109

emitter: SlackEventAdapter # The parent event adapter instance

110

endpoint: str # The URL endpoint for receiving events

111

package_info: str # User-agent string with version information

112

```

113

114

[Server Integration](./server-integration.md)

115

116

## Types

117

118

```python { .api }

119

class SlackEventAdapterException(Exception):

120

"""Base exception for all errors raised by the SlackClient library"""

121

def __init__(self, msg=None): ...

122

```

123

124

## Constants

125

126

```python { .api }

127

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

128

```