Slacker

0.14.0 · abandoned · verified Tue Apr 14

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `Slacker` with an API token from an environment variable, test the API connection, and send a simple message to a Slack channel. It also includes an example of fetching user lists. Ensure you set the `SLACK_API_TOKEN` environment variable with your workspace token and optionally `SLACK_CHANNEL` for message posting.

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}")

view raw JSON →