Want Claude 2's document analysis and AI capabilities inside Slack? You can build a custom integration using the Claude API and Slack's bot framework.
This isn't an official pre-built app. It's a custom integration you build yourself. Here's how to set it up.
## Why This Matters
Your team lives in Slack. Context lives in Slack. Documents get shared in Slack channels.
**Integrating Claude 2 into Slack means your team can analyze documents, get answers, and automate workflows without switching tools.** No more downloading PDFs, opening claude.ai in a browser, copy-pasting results back.
For operations teams, this reduces friction in document review, Q&A, and collaboration workflows.
## What You'll Build
This guide walks through building a Slack bot that:
- Responds to mentions with Claude 2 answers
- Analyzes uploaded files (PDFs, text, CSV)
- Maintains conversation context per channel
- Handles document summarization
- Works with slash commands
## Prerequisites
You'll need:
- Claude API access (sign up at console.anthropic.com)
- Slack workspace admin access
- Basic Python knowledge
- A server to host the bot (or use a service like Railway or Heroku)
## Step 1: Set Up Claude API Access
First, get your Claude API credentials.
**Get API Key**:
1. Go to console.anthropic.com
2. Create an account or sign in
3. Navigate to API Keys
4. Generate a new key
5. Save it securely (you'll need it later)
**Test API Access**:
```python
import anthropic
client = anthropic.Anthropic(
api_key="your-api-key-here"
)
message = client.messages.create(
model="claude-2",
max_tokens=1024,
messages=[
{"role": "user", "content": "Hello, Claude!"}
]
)
print(message.content)
```
If this works, you're ready to proceed.
## Step 2: Create Slack App
**Create New App**:
1. Go to api.slack.com/apps
2. Click "Create New App"
3. Choose "From scratch"
4. Name it "Claude Assistant"
5. Select your workspace
**Configure Bot Permissions**:
Under "OAuth & Permissions", add these scopes:
- `app_mentions:read` (see @mentions)
- `chat:write` (send messages)
- `files:read` (access uploaded files)
- `channels:history` (read channel messages)
- `groups:history` (read private channels)
**Enable Events**:
Under "Event Subscriptions":
1. Turn on "Enable Events"
2. Add bot user events:
- `app_mention` (when someone @mentions the bot)
- `file_shared` (when files are uploaded)
3. Save (you'll need a request URL, set that up in Step 3)
**Install App**:
1. Go to "Install App"
2. Click "Install to Workspace"
3. Authorize the app
4. Save the "Bot User OAuth Token"
## Step 3: Build the Integration
Here's a working Python implementation using Flask:
```python
import os
import anthropic
from flask import Flask, request, jsonify
from slack_sdk import WebClient
from slack_sdk.errors import SlackApiError
app = Flask(__name__)
# Initialize clients
slack_client = WebClient(token=os.environ["SLACK_BOT_TOKEN"])
claude_client = anthropic.Anthropic(
api_key=os.environ["ANTHROPIC_API_KEY"]
)
# Store conversation history per channel
conversations = {}
@app.route("/slack/events", methods=["POST"])
def slack_events():
data = request.json
# Verify Slack challenge
if "challenge" in data:
return jsonify({"challenge": data["challenge"]})
# Handle app mention
if data["event"]["type"] == "app_mention":
handle_mention(data["event"])
return jsonify({"status": "ok"})
def handle_mention(event):
channel = event["channel"]
user = event["user"]
text = event["text"]
# Remove bot mention from text
query = text.split(">", 1)[1].strip() if ">" in text else text
# Get response from Claude
try:
response = claude_client.messages.create(
model="claude-2",
max_tokens=2000,
messages=[{"role": "user", "content": query}]
)
answer = response.content[0].text
# Send response to Slack
slack_client.chat_postMessage(
channel=channel,
text=answer,
thread_ts=event.get("thread_ts", event["ts"])
)
except Exception as e:
slack_client.chat_postMessage(
channel=channel,
text=f"Sorry, I encountered an error: {str(e)}",
thread_ts=event.get("thread_ts", event["ts"])
)
if __name__ == "__main__":
app.run(port=3000)
```
**Set Environment Variables**:
```bash
export SLACK_BOT_TOKEN="xoxb-your-token"
export ANTHROPIC_API_KEY="your-claude-key"
```
## Step 4: Add File Analysis
Extend the bot to analyze uploaded files:
```python
@app.route("/slack/events", methods=["POST"])
def slack_events():
data = request.json
if "challenge" in data:
return jsonify({"challenge": data["challenge"]})
if data["event"]["type"] == "app_mention":
handle_mention(data["event"])
if data["event"]["type"] == "file_shared":
handle_file(data["event"])
return jsonify({"status": "ok"})
def handle_file(event):
file_id = event["file_id"]
channel = event["channel_id"]
try:
# Download file from Slack
file_info = slack_client.files_info(file=file_id)
file_url = file_info["file"]["url_private"]
# Download file content
headers = {"Authorization": f"Bearer {os.environ['SLACK_BOT_TOKEN']}"}
response = requests.get(file_url, headers=headers)
file_content = response.text
# Analyze with Claude
analysis = claude_client.messages.create(
model="claude-2",
max_tokens=3000,
messages=[{
"role": "user",
"content": f"Please analyze this document and provide a summary:\n\n{file_content}"
}]
)
# Post results
slack_client.chat_postMessage(
channel=channel,
text=f"Document Analysis:\n\n{analysis.content[0].text}"
)
except Exception as e:
print(f"Error analyzing file: {e}")
```
## Step 5: Deploy
You need to host this bot somewhere accessible to Slack.
**Option 1: Railway (Recommended)**
1. Push code to GitHub
2. Connect Railway to your repo
3. Add environment variables
4. Deploy
5. Use Railway URL in Slack event subscriptions
**Option 2: Heroku**
1. Create Heroku app
2. Configure environment variables
3. Deploy with Git
4. Use Heroku URL in Slack
**Option 3: Your Server**
1. Set up a server with Python
2. Use nginx or similar for HTTPS
3. Run the Flask app
4. Configure firewall for Slack IPs
## Real-World Use Cases
At The Operations Guide, we use this integration for:
**Contract Review in #legal**
- Team member uploads vendor contract
- @mentions Claude with "summarize this and flag any unusual terms"
- Claude analyzes and responds in thread
- Legal team reviews before formal analysis
**Code Review in #engineering**
- Developer shares code snippet
- @mentions Claude with "review this function for bugs"
- Claude provides feedback
- Developer iterates in the thread
**Document Q&A in #operations**
- Someone uploads quarterly report
- Multiple team members ask questions in thread
- Claude maintains context across questions
- Faster than reading full report individually
**Meeting Prep in #leadership**
- Upload board deck or briefing doc
- Ask Claude for key takeaways
- Get summary before meeting starts
- Everyone arrives better prepared
## Cost Considerations
Every Claude query costs API tokens. Estimate your costs:
**Typical Slack usage**:
- 50 questions per day: ~$2-3/month
- 20 document analyses per day: ~$4-6/month
- Total: ~$6-9/month
Compare to productivity gains from faster document review and Q&A.
## Limitations and Gotchas
**File Format Support**
Claude works best with plain text. Complex PDFs may need preprocessing.
**Response Time**
Claude takes 10-30 seconds. Set expectations with your team.
**Context Length**
Slack messages are short, but document uploads can be large. Watch your token usage.
**Rate Limits**
Claude API has rate limits. Build queuing if you expect high volume.
## Quick Takeaway
Integrating Claude 2 into Slack takes about 2 hours of development work. For teams that share and discuss documents in Slack, it eliminates workflow friction and speeds up document analysis by 3-5x.
Get Weekly Claude AI Insights
Join thousands of professionals staying ahead with expert analysis, tips, and updates delivered to your inbox every week.
Comments Coming Soon
We're setting up GitHub Discussions for comments. Check back soon!
Setup Instructions for Developers
Step 1: Enable GitHub Discussions on the repo
Step 2: Visit https://giscus.app and configure
Step 3: Update Comments.tsx with repo and category IDs