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.
- 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
- 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.
- Clone the repository and navigate to the directory.
- Create and activate a Python virtual environment:
python3 -m venv .venv source .venv/bin/activate - Install dependencies:
pip install -r requirements.txt
- 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-).
- Add the following OAuth scopes:
- Create a
.envfile:SLACK_BOT_TOKEN=xoxb-...
-
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.
-
Add OAuth Scopes:
- In your app settings, go to "OAuth & Permissions".
- Under "Scopes", add the following Bot Token Scopes:
channels:historygroups:historyim:historympim:historychannels:readgroups:readusers:readusers:read.emailteam:readfiles:read
-
Install the App to Your Workspace:
- In the "OAuth & Permissions" section, click "Install App to Workspace".
- Authorize the app when prompted.
-
Copy the Bot User OAuth Token:
- After installation, you’ll see a "Bot User OAuth Token" (it starts with
xoxb-). - Copy this token.
- After installation, you’ll see a "Bot User OAuth Token" (it starts with
-
Add the Token to Your
.envFile:- In your project directory, create a
.envfile (if it doesn’t exist). - Add the following line:
SLACK_BOT_TOKEN=xoxb-your-token-here
- In your project directory, create a
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
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.jsonfor resumable exports. - Handles Slack API rate limits robustly.
python slack_exporter.py- To export only specific channels, create
export_config.json:{ "channel_ids": ["C12345678", "C87654321"] }
Exports all user metadata to users.json and downloads user avatars to the avatars/ directory.
python export_users_metadata.pyExports all channel metadata (name, ID, is_member) to channels.json for reference or configuration.
python export_channels_metadata.pyPrints all channels and indicates whether the bot is a member of each.
python list_channels_metadata.pyThis 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.
- Supports ANSI and ISO A series page sizes.
- Custom fonts and page margins.
- Includes a user key page with avatars and user info.
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 1The output PDF is named based on the channel folder and page size.
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.
- 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.
MIT
Made with ☕ by Julian Bleecker.
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:
- Use SlackExporter to export your messages and files.
- Use
slack2pdf.pyto create a transcript PDF of the messages. - Use Files2Book to create a PDF book from the exported files directory.
- 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.