Six Degrees of Hack Club
A Slack bot that maps channel connections in the Hack Club workspace by analyzing channel mentions. This creates a graph of how channels reference each other, perfect for building a "six degrees of separation" visualization.
Web version here
Features
- Uses Slack WebSocket (Socket Mode) for real-time connection
- Recursively scans all channels in the workspace
- Memory-efficient: streams messages without storing them in RAM
- Writes connections to disk incrementally (batches of 5)
- Checkpoint system for resuming interrupted scans
- Channel cache to avoid rate limiting
- Debug mode for troubleshooting
- Outputs JSONL format with timestamps, message links, author info, and message previews
- Tracks total message count per channel
- SQLite conversion utility for easy querying
Prerequisites
- A Slack workspace (Hack Club in this case). Standalone or Enterprise Grid both work - see Enterprise Grid workspaces
- Admin access to create a Slack app
- Node.js installed (v18 or higher recommended)
Quick Setup with App Manifest
Step 1: Create App from Manifest
- Go to api.slack.com/apps
- Click "Create New App"
- Select "From an app manifest"
- Choose the workspace you want to map (on Enterprise Grid, pick the individual workspace, not the org)
- Select YAML tab
- Copy and paste the contents of
slack-app-manifest.yamlfrom this project - Click "Next" → Review the configuration → Click "Create"
Step 2: Get Your Tokens
Bot Token (xoxb-...)
- In your app settings, go to "OAuth & Permissions" (left sidebar)
- Click "Install to Workspace"
- Click "Allow"
- Copy the "Bot User OAuth Token" (starts with
xoxb-)
App Token (xapp-...)
- Go to "Basic Information" (left sidebar)
- Scroll down to "App-Level Tokens"
- Click "Generate Token and Scopes"
- Name it something like
socket-token - Add the scope:
connections:write - Click "Generate"
- Copy the token (starts with
xapp-)
Step 3: Configure Environment
-
Copy the example environment file:
cp .env.example .env -
Edit
.envand paste your tokens:SLACK_BOT_TOKEN=xoxb-your-bot-token-here SLACK_APP_TOKEN=xapp-your-app-token-here DEBUG=false CLEAR_CHANNEL_CACHE=false
Step 4: Install & Run
npm install
npm startEnterprise Grid Workspaces
The bot runs against a single workspace, including one that belongs to an Enterprise Grid org. No extra configuration is needed:
- The manifest ships with
org_deploy_enabled: false, which is the setting for a per-workspace install. Leave it alone. - When installing, select the individual workspace rather than installing the app org-wide.
- Message links are built from the workspace URL returned by
auth.test, so Grid workspaces correctly gethttps://<workspace>.enterprise.slack.com/archives/...instead of a.slack.comlink. SetSLACK_WORKSPACE_URLin.envonly if you need to override it.
The bot prints the workspace name, team ID, and link base at startup - check those match the workspace you meant to scan.
If the token came from an org-wide install, the bot warns at startup. That install scopes the token to every workspace at once, which changes how channel listing behaves. Reinstall to a single workspace.
Channels shared into the workspace from elsewhere in the org may not be joinable. Those are logged and skipped, and the scan continues.
Manual Setup (Alternative)
If you prefer to set up manually instead of using the manifest:
- Create a Slack App at api.slack.com/apps
- Enable Socket Mode and generate an app-level token
- Add these Bot Token Scopes:
channels:history- Read messages from public channelschannels:read- View basic channel infochannels:join- Join public channelsgroups:history- Read messages from private channels (optional)groups:read- View basic private channel info (optional)
- Install app to workspace and get tokens
- Follow steps 3-4 from Quick Setup
File Structure
sixdegreesofhackclub/
├── src/
│ ├── bot/ # Slack bot modules
│ │ ├── index.js # Main entry point
│ │ ├── config.js # Configuration and constants
│ │ ├── channels.js # Channel fetching and caching
│ │ ├── scanner.js # Message scanning logic
│ │ ├── checkpoint.js # Checkpoint management
│ │ └── output.js # Output file handling
│ │
│ └── cli/ # CLI tool modules
│ ├── index.js # CLI entry point
│ ├── graph.js # Graph data structure
│ ├── loader.js # JSONL data loader
│ └── display.js # Display formatting
│
├── utils/ # Utility scripts
│ └── convert-to-sqlite.js # Convert JSONL to SQLite database
│
├── package.json # Dependencies and scripts
├── .env # Your tokens (create from .env.example)
├── .env.example # Example environment config
├── slack-app-manifest.yaml # Slack app configuration
├── README.md # This file
├── LICENSE # AGPL-3.0 license
└── .gitignore # Git ignore rules
Generated files (gitignored):
├── channels-cache.json # Cached channel list
├── channel-links.jsonl # Output connections (JSONL format)
├── channel-metadata.json # Metadata and channel info
├── checkpoint.json # Resume state (deleted on completion)
└── channel-graph.db # SQLite database (generated by utils/convert-to-sqlite.js)Configuration Options
Environment Variables
SLACK_BOT_TOKEN- Your bot OAuth token (required)SLACK_APP_TOKEN- Your app-level token for Socket Mode (required)DEBUG- Set totruefor verbose output and no file writes (default:false)CLEAR_CHANNEL_CACHE- Set totrueto refresh channel cache (default:false)SLACK_WORKSPACE_URL- Optional override for the base URL in message links (default: detected viaauth.test)
Debug Mode (DEBUG=true)
When enabled:
- Prints all connections to stdout as JSON instead of writing to file
- Shows detailed batch information and message date ranges
- Displays sample messages from each channel
- Shows oldest message found in each channel
- Skips checkpoint saving/loading
- Skips metadata file generation
Useful for:
- Testing the bot on specific channels
- Troubleshooting missing links
- Verifying message scanning behavior
- Piping output to other tools
Channel Cache
The bot caches the full channel list to channels-cache.json to avoid rate limiting on subsequent runs.
To refresh the cache:
CLEAR_CHANNEL_CACHE=trueAfter refreshing, set it back to false.
Output Format
channel-links.jsonl
JSONL (JSON Lines) format - one connection per line:
{"from":"C0266FRGT","to":"C0266FRGV","fromName":"announcements","toName":"lounge","messageTs":"1471465905.000099","messageDate":"2016-08-17T20:31:45.000Z","messageLink":"https://hackclub.slack.com/archives/C0266FRGT/p1471465905000099","authorUserId":"U0266FRGP","messageText":"Check out the discussion in <#C0266FRGV>"}Each connection includes:
from/to- Channel IDsfromName/toName- Channel namesmessageTs- Slack timestampmessageDate- ISO 8601 formatted datemessageLink- Direct link to the messageauthorUserId- Slack user ID who posted the messagemessageText- First 200 characters of the message (for context)
channel-metadata.json
Contains workspace metadata and channel information:
{
"workspace": "Hack Club",
"generatedAt": "2025-10-26T12:00:00.000Z",
"totalChannels": 8348,
"processingTimeSeconds": "3600.00",
"outputFile": "channel-links.jsonl",
"channels": {
"C123456": {
"id": "C123456",
"name": "general",
"messageCount": 15420
}
}
}checkpoint.json
Saved automatically every 10k messages and after each channel. Allows resuming if interrupted:
{
"lastChannelIndex": 42,
"lastChannelId": "C123456",
"lastMessageCount": 15000,
"timestamp": "2025-10-26T12:00:00.000Z"
}How It Works
-
Channel Discovery:
- Loads channel list from cache if available
- Otherwise fetches all public/private channels via
conversations.list - Caches results to avoid rate limiting
-
Message Scanning:
- For each channel, fetches message history in batches of 1000
- Uses regex to find channel mentions:
<#CHANNELID>,<#CHANNELID|name>,<#CHANNELID|> - Only stores the first reference between any two channels
- Messages are processed in streaming fashion (not stored in RAM)
-
Incremental Writing:
- Connections written to disk every 5 links found
- Checkpoint saved every 10k messages and after each channel
- Memory usage stays minimal regardless of workspace size
-
Resume Capability:
- If interrupted (Ctrl+C), checkpoint is saved
- Next run automatically resumes from last checkpoint
- Checkpoint deleted on successful completion
Rate Limiting
Built-in delays to respect Slack API limits:
- 100ms between message history pages
- 200ms between channels
- Automatic retry on rate limit errors
The Slack API has rate limits for conversations.list which is why the channel cache is important.
Usage Examples
Normal Run
npm startDebug Mode (Test on First Channel)
# Set in .env
DEBUG=true
npm startRefresh Channel Cache
# Set in .env
CLEAR_CHANNEL_CACHE=true
npm start
# Then set back to false
CLEAR_CHANNEL_CACHE=falseResume After Interruption
Simply run again - it will automatically resume from checkpoint:
npm startTroubleshooting
"not_in_channel" errors
The bot automatically attempts to join public channels. For private channels, manually invite the bot:
/invite @Six Degrees MapperRate limit errors
If you hit rate limits frequently:
- Use the channel cache (don't set
CLEAR_CHANNEL_CACHE=trueunnecessarily) - Increase delays in
src/bot/config.jsif needed (editDELAY_BETWEEN_MESSAGE_PAGESandDELAY_BETWEEN_CHANNELS)
Missing recent messages
The bot scans from newest to oldest. If recent channel mentions are missing:
- Check if they use the format
<#CHANNELID>(the bot detects this) - Mentions in thread replies are NOT scanned (only top-level messages)
- Plain text like "check out #general" without the link format won't be detected
Out of memory
The bot is designed to be memory-efficient:
- Messages are NOT stored in RAM
- Only a small Set of channel IDs per channel is kept
- Connections written to disk in batches of 5
If you still hit memory issues, there may be an extremely large number of unique channel references in a single channel.
Permissions
The bot requires these permissions:
channels:history- Read public channel messageschannels:read- List public channelschannels:join- Auto-join public channelsgroups:history- Read private channel messages (if invited)groups:read- List private channels (if invited)
For private channels, the bot must be explicitly invited.
SQLite Database
Convert the JSONL output to a SQLite database for easier querying:
node utils/convert-to-sqlite.jsThis creates channel-graph.db with the following tables:
Tables
workspace - Workspace metadata
key(TEXT) - Metadata keyvalue(TEXT) - Metadata value
channels - All channel information
id(TEXT) - Channel IDname(TEXT) - Channel namename_normalized(TEXT) - Normalized channel namecreated(INTEGER) - Unix timestamp of creationcreator(TEXT) - User ID of creatoris_private(INTEGER) - Is private channel (0/1)is_archived(INTEGER) - Is archived (0/1)is_general(INTEGER) - Is general channel (0/1)is_channel(INTEGER) - Is channel vs group (0/1)updated(INTEGER) - Last updated timestampmessage_count(INTEGER) - Total messages in channel
connections - Channel-to-channel mentions
id(INTEGER) - Auto-increment primary keyfrom_channel_id(TEXT) - Source channel IDto_channel_id(TEXT) - Target channel IDfrom_channel_name(TEXT) - Source channel nameto_channel_name(TEXT) - Target channel namemessage_ts(TEXT) - Slack message timestampmessage_date(TEXT) - ISO 8601 datemessage_link(TEXT) - Direct link to messageauthor_user_id(TEXT) - User who posted the messagemessage_text(TEXT) - First 200 chars of message
Views
channel_stats - Statistics per channel
- All channel fields plus:
outgoing_connections- Channels this one mentionsincoming_connections- Channels that mention this onetotal_connections- Sum of both
most_connected_channels - Channels ordered by total connections
connection_details - Connections with full channel metadata
Example Queries
-- Find channels with most messages
SELECT name, message_count
FROM channels
WHERE message_count > 0
ORDER BY message_count DESC
LIMIT 10;
-- Find most active users (by channel mentions)
SELECT author_user_id, COUNT(*) as mention_count
FROM connections
WHERE author_user_id IS NOT NULL
GROUP BY author_user_id
ORDER BY mention_count DESC
LIMIT 10;
-- Find connections with message context
SELECT from_channel_name, to_channel_name, message_text, message_date
FROM connections
WHERE message_text IS NOT NULL
LIMIT 10;
-- Channels with high engagement (connections per 1k messages)
SELECT
name,
message_count,
total_connections,
CAST(total_connections AS FLOAT) / NULLIF(message_count, 0) * 1000 as ratio
FROM channel_stats
WHERE message_count > 100
ORDER BY ratio DESC
LIMIT 10;Next Steps
Use the channel-links.jsonl file or SQLite database to build a web UI that:
- Visualizes the channel graph (D3.js, vis.js, Cytoscape.js)
- Implements pathfinding algorithms (BFS/Dijkstra)
- Shows all possible paths between two channels
- Calculates "degrees of separation" statistics
- Filters by date range or specific channels
- Identifies the most connected channels
- Finds isolated channel clusters
License
AGPL-3.0
License Change: This project was previously under MIT license up to commit d045308 (2025-10-28). As of October 28, 2025, all new contributions are under AGPL-3.0. The project as a whole is now AGPL-3.0.