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

  1. A Slack workspace (Hack Club in this case). Standalone or Enterprise Grid both work - see Enterprise Grid workspaces
  2. Admin access to create a Slack app
  3. Node.js installed (v18 or higher recommended)

Quick Setup with App Manifest

Step 1: Create App from Manifest

  1. Go to api.slack.com/apps
  2. Click "Create New App"
  3. Select "From an app manifest"
  4. Choose the workspace you want to map (on Enterprise Grid, pick the individual workspace, not the org)
  5. Select YAML tab
  6. Copy and paste the contents of slack-app-manifest.yaml from this project
  7. Click "Next" → Review the configuration → Click "Create"

Step 2: Get Your Tokens

Bot Token (xoxb-...)

  1. In your app settings, go to "OAuth & Permissions" (left sidebar)
  2. Click "Install to Workspace"
  3. Click "Allow"
  4. Copy the "Bot User OAuth Token" (starts with xoxb-)

App Token (xapp-...)

  1. Go to "Basic Information" (left sidebar)
  2. Scroll down to "App-Level Tokens"
  3. Click "Generate Token and Scopes"
  4. Name it something like socket-token
  5. Add the scope: connections:write
  6. Click "Generate"
  7. Copy the token (starts with xapp-)

Step 3: Configure Environment

  1. Copy the example environment file:

    cp .env.example .env
  2. Edit .env and 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 start

Enterprise 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 get https://<workspace>.enterprise.slack.com/archives/... instead of a .slack.com link. Set SLACK_WORKSPACE_URL in .env only 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:

  1. Create a Slack App at api.slack.com/apps
  2. Enable Socket Mode and generate an app-level token
  3. Add these Bot Token Scopes:
    • channels:history - Read messages from public channels
    • channels:read - View basic channel info
    • channels:join - Join public channels
    • groups:history - Read messages from private channels (optional)
    • groups:read - View basic private channel info (optional)
  4. Install app to workspace and get tokens
  5. 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 to true for verbose output and no file writes (default: false)
  • CLEAR_CHANNEL_CACHE - Set to true to refresh channel cache (default: false)
  • SLACK_WORKSPACE_URL - Optional override for the base URL in message links (default: detected via auth.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=true

After 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 IDs
  • fromName / toName - Channel names
  • messageTs - Slack timestamp
  • messageDate - ISO 8601 formatted date
  • messageLink - Direct link to the message
  • authorUserId - Slack user ID who posted the message
  • messageText - 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

  1. Channel Discovery:

    • Loads channel list from cache if available
    • Otherwise fetches all public/private channels via conversations.list
    • Caches results to avoid rate limiting
  2. 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)
  3. 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
  4. 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 start

Debug Mode (Test on First Channel)

# Set in .env
DEBUG=true

npm start

Refresh Channel Cache

# Set in .env
CLEAR_CHANNEL_CACHE=true

npm start

# Then set back to false
CLEAR_CHANNEL_CACHE=false

Resume After Interruption

Simply run again - it will automatically resume from checkpoint:

npm start

Troubleshooting

"not_in_channel" errors

The bot automatically attempts to join public channels. For private channels, manually invite the bot:

/invite @Six Degrees Mapper

Rate limit errors

If you hit rate limits frequently:

  1. Use the channel cache (don't set CLEAR_CHANNEL_CACHE=true unnecessarily)
  2. Increase delays in src/bot/config.js if needed (edit DELAY_BETWEEN_MESSAGE_PAGES and DELAY_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 messages
  • channels:read - List public channels
  • channels:join - Auto-join public channels
  • groups: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.js

This creates channel-graph.db with the following tables:

Tables

workspace - Workspace metadata

  • key (TEXT) - Metadata key
  • value (TEXT) - Metadata value

channels - All channel information

  • id (TEXT) - Channel ID
  • name (TEXT) - Channel name
  • name_normalized (TEXT) - Normalized channel name
  • created (INTEGER) - Unix timestamp of creation
  • creator (TEXT) - User ID of creator
  • is_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 timestamp
  • message_count (INTEGER) - Total messages in channel

connections - Channel-to-channel mentions

  • id (INTEGER) - Auto-increment primary key
  • from_channel_id (TEXT) - Source channel ID
  • to_channel_id (TEXT) - Target channel ID
  • from_channel_name (TEXT) - Source channel name
  • to_channel_name (TEXT) - Target channel name
  • message_ts (TEXT) - Slack message timestamp
  • message_date (TEXT) - ISO 8601 date
  • message_link (TEXT) - Direct link to message
  • author_user_id (TEXT) - User who posted the message
  • message_text (TEXT) - First 200 chars of message

Views

channel_stats - Statistics per channel

  • All channel fields plus:
  • outgoing_connections - Channels this one mentions
  • incoming_connections - Channels that mention this one
  • total_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.