Slacker
Slacker is a full-featured Python interface for the Slack API. The project is no longer actively maintained since July 2020, with version 0.14.0 being the last release. Users are advised to migrate to the official Slack Python SDK.
Warnings
- breaking The `os/slacker` GitHub repository has been archived since July 2020, and the project is no longer actively maintained. No further updates or bug fixes will be provided.
- breaking Version 0.13.0 dropped support for Python 2.6. Future versions (though none are expected) would likely continue to drop older Python 2.x versions. [from release notes]
- gotcha In version 0.13.0, the `utils` module was renamed to `utilities`. Code importing `slacker.utils` will break. [from release notes]
- gotcha Exposing API tokens directly in code is a security risk. Slack API tokens can be automatically revoked if exposed in public repositories.
- gotcha Due to the library being unmaintained, it may not be compatible with newer Slack API features, changes in API endpoints, or updated security requirements from Slack. You might encounter unexpected errors or limitations with current Slack functionalities.
Install
-
pip install slacker
Imports
- Slacker
from slacker import Slacker
Quickstart
import os
from slacker import Slacker
# Get your Slack API token from an environment variable
slack_token = os.environ.get('SLACK_API_TOKEN', 'YOUR_SLACK_API_TOKEN')
if not slack_token or slack_token == 'YOUR_SLACK_API_TOKEN':
print("Error: SLACK_API_TOKEN environment variable not set or is default. Please set it.")
else:
try:
slack = Slacker(slack_token)
# Test API connection
response = slack.api.test()
if response.successful:
print(f"Successfully connected to Slack API (Team: {slack.team.info().body['team']['name']}).")
# Send a message to a channel (replace '#general' with your target channel)
channel = os.environ.get('SLACK_CHANNEL', '#general')
message = "Hello from Slacker! This library is no longer maintained, consider migrating to the official Slack SDK."
post_response = slack.chat.post_message(channel, message)
if post_response.successful:
print(f"Message sent to {channel}.")
else:
print(f"Failed to send message: {post_response.error}")
# Get users list example
users_response = slack.users.list()
if users_response.successful:
print(f"Found {len(users_response.body['members'])} users.")
else:
print(f"Failed to retrieve users: {users_response.error}")
else:
print(f"Failed to connect to Slack API: {response.error}")
except Exception as e:
print(f"An error occurred: {e}")