Export a single Slack private channel to JSON or text format, with support for date range filtering and thread preservation.
- Install dependencies:
pip install -r requirements.txt-
Create a Slack App and get an OAuth token:
- Go to https://api.slack.com/apps
- Create a new app or select existing app
- Add OAuth scopes:
groups:historyandgroups:read(for private channels) - Install app to your workspace
- Copy the "Bot User OAuth Token" (starts with
xoxb-)
-
Configure your environment:
# Copy the example file
cp .env.example .env
# Edit .env and add your token
# SLACK_BOT_TOKEN=xoxb-your-actual-token
# SLACK_CHANNEL_ID=C1234567890 # Optional: set a default channel- Add the bot to the private channel you want to export:
- In Slack, go to the channel
- Type
/invite @YourBotName
After setting up your .env file:
# Export entire channel history as JSON
python export_channel.py C1234567890 --output export.json
# Or use the default channel from .env
python export_channel.py --output export.json
# Export as text file
python export_channel.py C1234567890 --output export.txt --format text
# Export with date range
python export_channel.py C1234567890 --output export.json \
--start-date 2024-01-01 --end-date 2024-12-31If SLACK_BOT_TOKEN is not set in your .env file, you'll be prompted securely:
python export_channel.py C1234567890 --output export.json
Enter Slack Bot Token: [input hidden]Note: The token is never passed as a command-line argument to prevent it from being stored in shell history or visible in process listings.
In Slack:
- Right-click on the channel name
- Select "View channel details"
- Scroll to bottom - the Channel ID is shown there
Or use the channel name to find it via API.
Contains full message objects with metadata, including nested thread replies under thread_replies key.
Human-readable format with timestamps, usernames, and indented thread replies:
[2024-01-15 10:30:45] U123456
Hello, this is a message
↳ [2024-01-15 10:31:20] U789012
This is a reply in the thread
================================================================================
- The bot must be a member of the private channel to access it
- Rate limits apply (typically 50+ requests per minute)
- Large channels may take several minutes to export
- Reactions, emojis metadata, and attachments are not exported