A FastAPI-based web service and CLI tool for fetching and formatting Slack thread conversations. This tool retrieves Slack threads via permalink URLs and returns them as formatted plain text, making them easy to read and process.
- FastAPI Web Service: HTTP API endpoint for fetching Slack threads
- CLI Tool: Command-line script for direct thread retrieval
- Claude Code Integration: Custom slash command for seamless use within Claude Code
- Docker Support: Containerized deployment with Red Hat UBI base image
- Clean Formatting: Converts Slack threads into readable conversation format
- User Name Resolution: Automatically resolves Slack user IDs to real names
- Python 3.11+
- Slack Bot Token (
xoxb-...) - Slack User Token (
xoxp-...)
# Clone the repository
git clone <repository-url>
cd slack-formatter
# Install dependencies
pip install -r requirements.txt
# Set environment variables
export SLACK_TOKEN=xoxb-your-bot-token
export USER_TOKEN=xoxp-your-user-token# Build the image
docker build -t slack-formatter .
# Run the container
docker run -p 8000:8000 \
-e SLACK_TOKEN=xoxb-your-bot-token \
-e USER_TOKEN=xoxp-your-user-token \
slack-formatterThe application requires two environment variables:
| Variable | Description | Example |
|---|---|---|
SLACK_TOKEN |
Slack Bot Token | xoxb-... |
USER_TOKEN |
Slack User Token | xoxp-... |
Note: The application will crash at startup if these environment variables are not set.
Start the server:
# Development mode with auto-reload
uvicorn app:app --reload
# Production mode
uvicorn app:app --host 0.0.0.0 --port 8000Access the API:
curl "http://localhost:8000/thread?url=https://workspace.slack.com/archives/CHANNEL_ID/pTIMESTAMP"python fetch_conversation.py "https://workspace.slack.com/archives/CHANNEL_ID/pTIMESTAMP"Example:
python fetch_conversation.py "https://redhat-internal.slack.com/archives/CB95J6R4N/p1764683404081219"docker run -p 8000:8000 \
-e SLACK_TOKEN=$SLACK_TOKEN \
-e USER_TOKEN=$USER_TOKEN \
slack-formatterThen access via curl:
curl "http://localhost:8000/thread?url=https://workspace.slack.com/archives/CHANNEL_ID/pTIMESTAMP"This repository includes a custom slash command for use with Claude Code.
The /slack_thread command fetches and summarizes Slack conversations directly within your Claude Code session.
Usage:
/slack_thread https://workspace.slack.com/archives/CHANNEL_ID/pTIMESTAMP
Example:
/slack_thread https://redhat-internal.slack.com/archives/CB95J6R4N/p1764683404081219
What it does:
- Fetches the Slack thread using the production API endpoint
- Returns the formatted conversation
- Claude automatically summarizes the conversation
The slash command is defined in .claude/commands/slack_thread.md and uses the production API at:
https://slack-formatter-slack-formatter.apps.artc2023.pc3z.p1.openshiftapps.com
Fetch and format a Slack thread.
Query Parameters:
url(required): Slack permalink URL
Example Request:
curl "http://localhost:8000/thread?url=https://workspace.slack.com/archives/CB95J6R4N/p1764683404081219"Example Response:
- John Doe: Hey team, we need to discuss the deployment
- Jane Smith: I agree, let's schedule a meeting
- John Doe: How about tomorrow at 2pm?
- Jane Smith: Works for me!
Error Responses:
404 Not Found: Thread not found or invalid URL format500 Internal Server Error: Missing environment variables
API information and usage instructions.
Example Request:
curl http://localhost:8000/-
Permalink Parsing: Extracts channel ID and timestamp from Slack permalink URLs
- Format:
https://{workspace}.slack.com/archives/{CHANNEL_ID}/p{TIMESTAMP} - Timestamp conversion:
1234567890123456→1234567890.123456
- Format:
-
Thread Retrieval: Uses Slack API's
conversations.repliesendpoint to fetch all messages in the thread -
User Resolution: Resolves Slack user IDs to real names using the
users.infoendpoint (with caching) -
Formatting: Converts messages to readable format:
- Username: Message text
slack-formatter/
├── .claude/
│ └── commands/
│ └── slack_thread.md # Claude Code slash command definition
├── resources/ # OpenShift deployment manifests
│ ├── buildconfig.yaml
│ ├── deploymentconfig.yaml
│ ├── is.yaml
│ ├── route.yaml
│ └── service.yaml
├── summarizerlib/
│ ├── __init__.py
│ └── slack.py # Core Slack integration logic
├── app.py # FastAPI application
├── fetch_conversation.py # CLI tool
├── Dockerfile # Container build instructions
├── requirements.txt # Python dependencies
└── README.md
The resources/ directory contains OpenShift manifests for deploying to OpenShift:
# Apply all manifests
oc apply -f resources/
# The deployment expects an existing secret named 'slack-credentials' with keys:
# - slack-token
# - user-token# Install development dependencies
pip install -r requirements.txt
# Run the application
python fetch_conversation.py "https://workspace.slack.com/archives/CHANNEL/pTIMESTAMP"# Build Docker image
docker build -t slack-formatter:latest .
# Run in production mode
docker run -d \
-p 8000:8000 \
-e SLACK_TOKEN=$SLACK_TOKEN \
-e USER_TOKEN=$USER_TOKEN \
--name slack-formatter \
slack-formatter:latest