slack

📁 sepehr500/skills 📅 6 days ago
2
总安装量
2
周安装量
#63067
全站排名
安装命令
npx skills add https://github.com/sepehr500/skills --skill slack

Agent 安装分布

amp 2
claude-code 2
github-copilot 2
codex 2
kimi-cli 2
gemini-cli 2

Skill 文档

Slack Integration

Interact with Slack on the user’s behalf using the Python Slack SDK – read messages, send replies, download and upload files.

Setup

Ensure the Python Slack SDK is installed:

pip install slack-sdk

Authentication

Use the Slack token from $SLACK_TOKEN environment variable. If not available, ask the user to provide it.

Required scopes (add via https://api.slack.com/apps -> OAuth & Permissions -> User Token Scopes):

  • search:read – search messages and files (preferred method)
  • users:read – look up users (required for users.list)
  • users:read.email – access email addresses in user profiles (optional)
  • im:history, im:read – read DMs
  • im:write, chat:write – send messages
  • channels:history, channels:read – read channels (optional)
  • files:read – download files
  • files:write – upload files

Python Slack SDK Client

A reusable client module is available at ~/.claude/skills/slack/scripts/slack_client.py.

CLI Usage

# Test authentication
python ~/.claude/skills/slack/scripts/slack_client.py auth

# Search messages
python ~/.claude/skills/slack/scripts/slack_client.py search "from:me to:username" --count 5

# List users
python ~/.claude/skills/slack/scripts/slack_client.py users

# Find a user by name
python ~/.claude/skills/slack/scripts/slack_client.py find-user "Alice"

# List conversations (DMs)
python ~/.claude/skills/slack/scripts/slack_client.py conversations --types im

# Get DM channel with user
python ~/.claude/skills/slack/scripts/slack_client.py dm-channel U12345

# Read messages from channel
python ~/.claude/skills/slack/scripts/slack_client.py read D67890 --limit 10

# Send a message
python ~/.claude/skills/slack/scripts/slack_client.py send D67890 "Hello there!"

Module Usage (inline Python)

import sys
sys.path.insert(0, str(Path.home() / ".claude/skills/slack/scripts"))
from slack_client import (
    test_auth, search_messages, list_users, find_user,
    get_dm_channel, read_messages, send_message,
    get_file_info, download_file, upload_file
)

# Test auth
auth = test_auth()
print(f"Authenticated as {auth['user']}")

# Search messages
messages = search_messages("from:me to:alice", count=5)
for msg in messages:
    print(f"{msg['ts']}: {msg['text']}")

# Find user and send message
user = find_user("Alice")
if user:
    channel = get_dm_channel(user['id'])
    result = send_message(channel, "Hello Alice!")
    print(f"Sent message: {result['ts']}")

Common Operations

Search messages (preferred method)

Use search to find messages without needing to look up user/channel IDs:

python ~/.claude/skills/slack/scripts/slack_client.py search "from:me to:alice" --count 5 --sort timestamp --sort-dir desc

Search operators:

  • from:me – messages you sent
  • from:username – messages from a specific user
  • to:username – messages in DMs with a user
  • in:channel – messages in a specific channel
  • has:link / has:file – messages with links or files
  • before:YYYY-MM-DD / after:YYYY-MM-DD – date filters

List all users

python ~/.claude/skills/slack/scripts/slack_client.py users

Find a user by name

python ~/.claude/skills/slack/scripts/slack_client.py find-user "Alice"

Get DM channel with a user

python ~/.claude/skills/slack/scripts/slack_client.py dm-channel U_ALICE_ID

Read recent messages from a DM

python ~/.claude/skills/slack/scripts/slack_client.py read D_CHANNEL_ID --limit 10

Send a message

python ~/.claude/skills/slack/scripts/slack_client.py send D_CHANNEL_ID "Your message here"

Download a file

from slack_client import get_file_info, download_file

info = get_file_info("FILE_ID")
download_file(info['url_private_download'], "/tmp/downloaded_file")

Upload a file

from slack_client import upload_file

upload_file("/tmp/myfile.txt", "D_CHANNEL_ID", title="My File", initial_comment="Here's the file!")

Workflow

When the user asks to interact with Slack:

  1. Verify token: Run python ~/.claude/skills/slack/scripts/slack_client.py auth
  2. Find messages: Use search command with operators like from:me to:username
  3. Send messages: Use send command with channel ID (get from search results or dm-channel)
  4. Handle files: Download or upload files as needed

Note: Prefer search over the multi-step process of users -> conversations -> read. Search is simpler and supports powerful query operators.