Skip to content

SlackExporter is a Python toolkit for exporting and archiving Slack workspace data. It enables administrators to extract messages, files, user info, and avatars from selected channels, with robust handling of Slack API rate limits and checkpointing for resumable exports. Use it to create a complete, searchable, and printable archives.

Notifications You must be signed in to change notification settings

bleeckerj/Slack2Book

Repository files navigation

SlackExporter

A robust toolkit for exporting Slack workspace data, including messages, files, user metadata, and avatars. Designed for administrators who need to archive or analyze Slack content. Which is another way of saying that this is a tool for persisting Slack data outside of Slack, for posterity, analysis, or just because you want to have a tangible copy that weighs something to represent the effort, time, sweat, and tears that went into realizing a dream, or perhaps your bosses dream.

Features

  • Export messages from public and private channels where the bot is a member
  • Download all files (attachments) shared in exported channels
  • Export all user metadata and download user avatars
  • Channel-level checkpointing for resumable exports
  • Selective channel export via configuration file
  • Robust handling of Slack API rate limits

Consists of the following tools:

  • slack_exporter.py — Export messages and files from channels, save user metadata and avatars, handle rate limits.
  • export_users_metadata.py — Export all user metadata and download user avatars.
  • export_channels_metadata.py — Export all channel metadata (name, ID, is_member).
  • list_channels_metadata.py — Print all channels and indicate bot membership.
  • slack2pdf.py — Convert Slack JSON exports into printable PDF transcripts with avatars and message text. See detailed usage and options for slack2pdf.py in README_slack2pdf.md.
  • resize_avatars.py — Resize avatars to 168x168 at 300 DPI for PDF transcripts.
  • inspect_messages_json.py — Report total messages and earliest/latest timestamps for a messages.json.
  • sample_messages_json.py — Print first/last N sample messages from a messages.json.
  • count_messages_with_files.py — Count messages that include file attachments.
  • run-on-all.sh — Batch-run the PDF transcript generator for every messages.json.

Setup

  1. Clone the repository and navigate to the directory.
  2. Create and activate a Python virtual environment:
    python3 -m venv .venv
    source .venv/bin/activate
  3. Install dependencies:
    pip install -r requirements.txt
  4. Create a Slack App:
    • Add the following OAuth scopes: channels:history, groups:history, im:history, mpim:history, channels:read, groups:read, users:read, users:read.email, team:read, files:read.
    • Install the app to your workspace and copy the Bot User OAuth Token (starts with xoxb-).
  5. Create a .env file:
    SLACK_BOT_TOKEN=xoxb-...

How to Obtain Your Slack Bot OAuth Token

  1. Create a Slack App:

    • Go to https://api.slack.com/apps and click "Create New App".
    • Choose "From scratch" and give your app a name and select your workspace.
  2. Add OAuth Scopes:

    • In your app settings, go to "OAuth & Permissions".
    • Under "Scopes", add the following Bot Token Scopes:
      • channels:history
      • groups:history
      • im:history
      • mpim:history
      • channels:read
      • groups:read
      • users:read
      • users:read.email
      • team:read
      • files:read
  3. Install the App to Your Workspace:

    • In the "OAuth & Permissions" section, click "Install App to Workspace".
    • Authorize the app when prompted.
  4. Copy the Bot User OAuth Token:

    • After installation, you’ll see a "Bot User OAuth Token" (it starts with xoxb-).
    • Copy this token.
  5. Add the Token to Your .env File:

    • In your project directory, create a .env file (if it doesn’t exist).
    • Add the following line:
      SLACK_BOT_TOKEN=xoxb-your-token-here
      

Note:
The bot must be invited to each channel (public or private) you wish to export from. Use /invite @your-bot-name in Slack to add it to channels

Scripts

slack_exporter.py

Exports messages and files from channels where the bot is a member (or from channels specified in export_config.json).

  • Downloads all files shared in messages to the files/ directory.
  • Saves user metadata and avatars.
  • Tracks exported channels in exported_channels.json for resumable exports.
  • Handles Slack API rate limits robustly.

Usage

python slack_exporter.py
  • To export only specific channels, create export_config.json:
    {
      "channel_ids": ["C12345678", "C87654321"]
    }

export_users_metadata.py

Exports all user metadata to users.json and downloads user avatars to the avatars/ directory.

Usage

python export_users_metadata.py

export_channels_metadata.py

Exports all channel metadata (name, ID, is_member) to channels.json for reference or configuration.

Usage

python export_channels_metadata.py

list_channels_metadata.py

Prints all channels and indicates whether the bot is a member of each.

Usage

python list_channels_metadata.py

Simple Slack PDF Transcript

This repo also includes slack2pdf.py, a script to convert the Slack JSON exports that the above tools produce into printable PDF files that are like running transcripts including user avatars, timestamps, and message text.

This script makes the books (almost — no covers, no representation of the visual assets). To do the visual assets you'll want to look at the pdf-to-grid-of-images repository. To do the covers — well...at the moment, you'll want to do that by hand!

You could also look at the repository Files2Book which you can then point at the directory containing the files for a specific channel. Files2Book will then create a PDF representing the files. It will do this by heuristically converting each file into a page or pages in that PDF. It can handle most file types that would have a reasonable representation as a page in a book, with no specific semantics other than I suppose what you might expect: an image becomes an image page, a PDF becomes one or more PDF pages, a video becomes an overview grid of frames from the video (with more complicated options available — read the README for Files2BOok for specifics). You can set margins and page sizes and so on. You can then use a PDF editing tool or similar to combine the Slack transcript PDF with the Files2Book generated PDF to create a more complete representation of the channel's content.

Features

  • Supports ANSI and ISO A series page sizes.
  • Custom fonts and page margins.
  • Includes a user key page with avatars and user info.

Usage

Run with:

python3 slack2pdf.py path/to/messages.json --page-size a4 --normal-font path/to/normal.ttf --bold-font path/to/bold.ttf --margin-top 1 --margin-bottom 1 --margin-left 1 --margin-right 1

The output PDF is named based on the channel folder and page size.

Integration with pdf-to-grid-of-images

The pdf-to-grid-of-images repository can be used to convert the PDFs, images, and movie files found in each channel’s files directory into pages of visual content for book assembly or further processing.
That project includes two Python scripts:

  • directory_to_images.py: Converts all pdfs, images and movies in a directory into page-ready image assets.
  • pdf_to_images.py: Converts PDF files into images for use as pages.
  • process_all_slack_dirs.py: Creates page images and combined PDFs along with flipbook pages representing video files, user indices, etc., for all the Slack content directories.

Use these tools to process the exported files from Slack channels and generate pages full of message transcripts and visual assets for your book or archive.

Notes

  • The bot must be a member of private channels to export their messages.
  • All output files (messages, users, avatars, files) are saved in the project directory or subdirectories.
  • For large workspaces, exporting may take significant time due to Slack API rate limits.

License

MIT

Made with ☕ by Julian Bleecker.

Next Steps: Turn Your Exported Files Into a Book

After exporting your Slack data and files, you may want to create a printable or shareable book from the exported files (images, PDFs, videos, etc.).
For this, check out the Files2Book repository. Files2Book can take the exported files from a Slack channel and automatically generate a PDF book, converting each file into one or more pages. It supports images, PDFs, and even videos (by generating grids of video frames).

Workflow Example:

  1. Use SlackExporter to export your messages and files.
  2. Use slack2pdf.py to create a transcript PDF of the messages.
  3. Use Files2Book to create a PDF book from the exported files directory.
  4. Optionally, combine the transcript PDF and the Files2Book PDF using a PDF editor for a complete archive.

See the Files2Book README for more details and usage instructions.

About

SlackExporter is a Python toolkit for exporting and archiving Slack workspace data. It enables administrators to extract messages, files, user info, and avatars from selected channels, with robust handling of Slack API rate limits and checkpointing for resumable exports. Use it to create a complete, searchable, and printable archives.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published