or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced.mdauth.mdchannels.mdchat.mdfiles.mdindex.mdinteractive.mdrtm.mdsearch.mdusers.md

index.mddocs/

0

# Slacker

1

2

A comprehensive Python interface for the Slack API, enabling developers to integrate with Slack's messaging, file sharing, user management, and team communication features. It offers a complete set of API endpoints wrapped in an object-oriented design with support for real-time messaging, file operations, authentication, and advanced features like reactions, pins, and webhooks.

3

4

## Package Information

5

6

- **Package Name**: slacker

7

- **Language**: Python

8

- **Installation**: `pip install slacker`

9

10

## Core Imports

11

12

```python

13

from slacker import Slacker

14

```

15

16

## Basic Usage

17

18

```python

19

from slacker import Slacker

20

21

# Initialize with your Slack API token

22

slack = Slacker('<your-slack-api-token-goes-here>')

23

24

# Send a message to a channel

25

response = slack.chat.post_message('#general', 'Hello fellow slackers!')

26

27

# Get users list

28

response = slack.users.list()

29

users = response.body['members']

30

31

# Upload a file

32

slack.files.upload('hello.txt')

33

34

# Advanced: Use requests.Session for connection pooling

35

from requests.sessions import Session

36

with Session() as session:

37

slack = Slacker(token, session=session)

38

slack.chat.post_message('#general', 'All these requests')

39

slack.chat.post_message('#general', 'go through')

40

slack.chat.post_message('#general', 'a single https connection')

41

```

42

43

## Architecture

44

45

The Slacker library is organized around a central `Slacker` client class that provides access to various Slack API endpoint groups. Each endpoint group is implemented as a separate class inheriting from `BaseAPI`:

46

47

- **Slacker**: Main client providing access to all API endpoints

48

- **BaseAPI**: Base class handling HTTP requests, rate limiting, and error handling

49

- **Response**: Wrapper for API responses with convenient access methods

50

- **Error**: Custom exception for API errors

51

- **Endpoint Classes**: Specialized classes for each API area (Chat, Users, Files, etc.)

52

53

This design allows for organized access to Slack's extensive API while providing common functionality like authentication, error handling, and rate limiting across all endpoints.

54

55

## Capabilities

56

57

### Authentication & Authorization

58

59

Handle user authentication, token validation, and OAuth flows for Slack applications.

60

61

```python { .api }

62

class Auth(BaseAPI):

63

def test(self): ...

64

def revoke(self, test=True): ...

65

66

class OAuth(BaseAPI):

67

def access(self, client_id, client_secret, code, redirect_uri=None): ...

68

def token(self, client_id, client_secret, code, redirect_uri=None, single_channel=None): ...

69

```

70

71

[Authentication & Authorization](./auth.md)

72

73

### Chat & Messaging

74

75

Send, update, and manage messages across channels, direct messages, and group conversations.

76

77

```python { .api }

78

class Chat(BaseAPI):

79

def post_message(self, channel, text=None, username=None, as_user=None, parse=None, link_names=None, attachments=None, unfurl_links=None, unfurl_media=None, icon_url=None, icon_emoji=None, thread_ts=None, reply_broadcast=None, blocks=None, mrkdwn=True): ...

80

def update(self, channel, ts, text, attachments=None, parse=None, link_names=False, as_user=None, blocks=None): ...

81

def delete(self, channel, ts, as_user=False): ...

82

def post_ephemeral(self, channel, text, user, as_user=None, attachments=None, link_names=None, parse=None, blocks=None): ...

83

```

84

85

[Chat & Messaging](./chat.md)

86

87

### Channel Management

88

89

Create, manage, and interact with public channels, private groups, and conversations.

90

91

```python { .api }

92

class Channels(BaseAPI):

93

def create(self, name): ...

94

def info(self, channel): ...

95

def list(self, exclude_archived=None, exclude_members=None): ...

96

def history(self, channel, latest=None, oldest=None, count=None, inclusive=False, unreads=False): ...

97

def join(self, name): ...

98

def leave(self, channel): ...

99

def invite(self, channel, user): ...

100

def kick(self, channel, user): ...

101

def get_channel_id(self, channel_name): ...

102

103

class Conversations(BaseAPI):

104

def create(self, name, user_ids=None, is_private=None): ...

105

def list(self, cursor=None, exclude_archived=None, types=None, limit=None): ...

106

def history(self, channel, cursor=None, inclusive=None, latest=None, oldest=None, limit=None): ...

107

def members(self, channel, cursor=None, limit=None): ...

108

```

109

110

[Channel Management](./channels.md)

111

112

### User Management

113

114

Manage users, user profiles, presence status, and user groups within your Slack workspace.

115

116

```python { .api }

117

class Users(BaseAPI):

118

def info(self, user, include_locale=False): ...

119

def list(self, presence=False): ...

120

def identity(self): ...

121

def set_active(self): ...

122

def get_presence(self, user): ...

123

def set_presence(self, presence): ...

124

def get_user_id(self, user_name): ...

125

126

class UserGroups(BaseAPI):

127

def list(self, include_disabled=None, include_count=None, include_users=None): ...

128

def create(self, name, handle=None, description=None, channels=None, include_count=None): ...

129

def update(self, usergroup, name=None, handle=None, description=None, channels=None, include_count=None): ...

130

```

131

132

[User Management](./users.md)

133

134

### File Operations

135

136

Upload, download, manage, and share files within Slack channels and conversations.

137

138

```python { .api }

139

class Files(BaseAPI):

140

def list(self, user=None, ts_from=None, ts_to=None, types=None, count=None, page=None, channel=None): ...

141

def info(self, file_, count=None, page=None): ...

142

def upload(self, file_=None, content=None, filetype=None, filename=None, title=None, initial_comment=None, channels=None, thread_ts=None): ...

143

def delete(self, file_): ...

144

def revoke_public_url(self, file_): ...

145

def shared_public_url(self, file_): ...

146

```

147

148

[File Operations](./files.md)

149

150

### Search & Discovery

151

152

Search across messages, files, and other content within your Slack workspace.

153

154

```python { .api }

155

class Search(BaseAPI):

156

def all(self, query, sort=None, sort_dir=None, highlight=None, count=None, page=None): ...

157

def files(self, query, sort=None, sort_dir=None, highlight=None, count=None, page=None): ...

158

def messages(self, query, sort=None, sort_dir=None, highlight=None, count=None, page=None): ...

159

```

160

161

[Search & Discovery](./search.md)

162

163

### Real-time Messaging

164

165

Connect to Slack's Real Time Messaging API for live message streams and event handling.

166

167

```python { .api }

168

class RTM(BaseAPI):

169

def start(self, simple_latest=False, no_unreads=False, mpim_aware=False): ...

170

def connect(self): ...

171

```

172

173

[Real-time Messaging](./rtm.md)

174

175

### Interactive Features

176

177

Manage reactions, starred items, pinned messages, and other interactive Slack features.

178

179

```python { .api }

180

class Reactions(BaseAPI):

181

def add(self, name, file_=None, file_comment=None, channel=None, timestamp=None): ...

182

def get(self, file_=None, file_comment=None, channel=None, timestamp=None, full=None): ...

183

def list(self, user=None, full=None, count=None, page=None): ...

184

def remove(self, name, file_=None, file_comment=None, channel=None, timestamp=None): ...

185

186

class Stars(BaseAPI):

187

def add(self, file_=None, file_comment=None, channel=None, timestamp=None): ...

188

def list(self, user=None, count=None, page=None): ...

189

def remove(self, file_=None, file_comment=None, channel=None, timestamp=None): ...

190

191

class Pins(BaseAPI):

192

def add(self, channel, file_=None, file_comment=None, timestamp=None): ...

193

def remove(self, channel, file_=None, file_comment=None, timestamp=None): ...

194

def list(self, channel): ...

195

```

196

197

[Interactive Features](./interactive.md)

198

199

### Advanced Features

200

201

Additional Slack functionality including webhooks, dialogs, presence management, Do Not Disturb settings, reminders, team administration, bot management, migration utilities, and direct messaging.

202

203

```python { .api }

204

class IncomingWebhook:

205

def post(self, data): ...

206

207

class Dialog(BaseAPI):

208

def open(self, dialog, trigger_id): ...

209

210

class Presence(BaseAPI):

211

def set(self, presence): ...

212

213

class DND(BaseAPI):

214

def team_info(self, users=None): ...

215

def set_snooze(self, num_minutes): ...

216

def info(self, user=None): ...

217

def end_dnd(self): ...

218

def end_snooze(self): ...

219

220

class Reminders(BaseAPI):

221

def add(self, text, time, user=None): ...

222

def complete(self, reminder): ...

223

def delete(self, reminder): ...

224

def info(self, reminder): ...

225

def list(self): ...

226

```

227

228

[Advanced Features](./advanced.md)

229

230

## Types

231

232

```python { .api }

233

class Slacker:

234

"""

235

Main Slack API client.

236

237

Args:

238

token (str): Slack API token

239

incoming_webhook_url (str, optional): URL for incoming webhooks

240

timeout (int): HTTP request timeout in seconds (default: 10)

241

http_proxy (str, optional): HTTP proxy URL

242

https_proxy (str, optional): HTTPS proxy URL

243

session (requests.Session, optional): Custom requests session for connection pooling

244

rate_limit_retries (int): Number of retries for rate-limited requests (default: 0)

245

"""

246

def __init__(self, token, incoming_webhook_url=None, timeout=DEFAULT_TIMEOUT, http_proxy=None, https_proxy=None, session=None, rate_limit_retries=DEFAULT_RETRIES): ...

247

248

class Response:

249

"""

250

Wrapper for Slack API responses.

251

252

Attributes:

253

raw (str): Raw response text

254

body (dict): Parsed JSON response

255

successful (bool): Whether the API call was successful

256

error (str, optional): Error message if unsuccessful

257

"""

258

def __init__(self, body): ...

259

def __str__(self): ...

260

261

class Error(Exception):

262

"""Custom exception for Slack API errors."""

263

pass

264

265

class BaseAPI:

266

"""

267

Base class for all API endpoint classes.

268

269

Args:

270

token (str, optional): Slack API token

271

timeout (int): HTTP request timeout (default: 10)

272

proxies (dict, optional): Proxy configuration

273

session (requests.Session, optional): Custom session

274

rate_limit_retries (int): Rate limit retry count (default: 0)

275

"""

276

def __init__(self, token=None, timeout=DEFAULT_TIMEOUT, proxies=None, session=None, rate_limit_retries=DEFAULT_RETRIES): ...

277

def get(self, api, **kwargs): ...

278

def post(self, api, **kwargs): ...

279

```

280

281

## Utility Functions

282

283

```python { .api }

284

def get_api_url(method):

285

"""

286

Build Slack API URL for given method.

287

288

Args:

289

method (str): API method name (e.g., 'chat.postMessage')

290

291

Returns:

292

str: Complete API URL

293

"""

294

295

def get_item_id_by_name(list_dict, key_name):

296

"""

297

Find item ID by name in list of dictionaries.

298

299

Args:

300

list_dict (list): List of dictionaries with 'name' and 'id' keys

301

key_name (str): Name to search for

302

303

Returns:

304

str or None: Item ID if found, None otherwise

305

"""

306

```