A python slack exporter
Based on the slack exporter provided by rohanshekhar, with ideas borrowed from the one by dcaslin for the file download logic.
The following improvements have been made to the original slack exporter:
- Fixed a bug that caused 'public channels' to be ignored when the downloaded archive is viewed with slack-export-viewer
- Added support for downloading files posted in channels (note these files aren't shown by slack-export-viewer as that requires changes to be made to the viewer.
- Increased the maximum number of channels/DMs/Groups exported from 100 to 1000 (the maximum currently allowed by the Slack API)
- Updated documentation
In contrast to dcaslin's slack exporter, the files generated by this exporter can be browsed using slack-export-viewer
The included script 'slack_export.py' works with a provided token to export Channels, Private Channels, Direct Messages and Multi Person Messages.
This script finds all channels, private channels and direct messages that your user participates in, downloads the complete history for those converations and writes each conversation out to seperate json files.
This user centric history gathering is nice because the official slack data exporter only exports public channels.
There may be limitations on what you can export based on the paid status of your slack account.
This use of the API is blessed by Slack : https://get.slack.help/hc/en-us/articles/204897248
" If you want to export the contents of your own private groups and direct messages please see our API documentation."
Dcaslin has written a nice guide on how to create your User API token. This guide can be found here: https://github.com/dcaslin/slack-export#creating-your-app-and-obtaining-a-token
This tool requires at least Python 3.6. In addition the following 'pip' packages need to be installed
pip3 install slack_api # https://pypi.org/project/slack-sdk/
pip3 install pick # https://pypi.org/project/pick/
# Export all Channels and DMs
python3 slack_export.py --token <token>...
# Export all Channels and DMs and download files posted in channels
python3 slack_export.py --token <token> --downloadFiles
# List the Channels and DMs available for export
python3 slack_export.py --token <token>... --dryRun
# Prompt you to select the Channels and DMs to export
python3 slack_export.py --token <token>... --prompt
# Generate a `slack_export.zip` file for use with slack-export-viewer
python3 slack_export.py --token <token>... --zip slack_export
When the --downloadFiles
option is specified, files posted in the channels are stored in the <channel_name>/files
directory inside the export. Filenames are prefixed with a timestamp of the message to which they are attached to prevent filename conflicts.
Downloaded files are not visible when the export is browsed with slack-export-viewer as this tool currently does not have support for embedded files.
Please note that simultaneous use of --downloadFiles
and --zip
is not recommended as this will, in most cases result in a huge zip-file being created.
This script exports all Channels and DMs by default.
To export only certain conversations, use one or more of the following arguments:
-
--publicChannels [CHANNEL_NAME [CHANNEL_NAME ...]]
Export Public Channels
(optionally filtered by the given channel names) -
--groups [GROUP_NAME [GROUP_NAME ...]]
Export Private Channels and Group DMs
(optionally filtered by the given group names) -
--directMessages [USER_NAME [USER_NAME ...]]
Export 1:1 DMs
(optionally filtered by the given user names) -
--prompt
Prompt you to select the conversations to export
(Any channel/group/user names specified with the other arguments take precedence.)
# Export only Public Channels
python slack_export.py --token xoxs-123... --publicChannels
# Export only the "General" and "Random" Public Channels
python slack_export.py --token xoxs-123... --publicChannels General Random
# Export only Private Channels and Group DMs, but save files posted in channels as well
python slack_export.py --token xoxs-123... --groups --downloadFiles
# Export only the "my_private_channel" Private Channel
python slack_export.py --token xoxs-123... --groups my_private_channel
# Export only 1:1 DMs
python slack_export.py --token xoxs-123... --directMessages
# Export only 1:1 DMs with jane_smith and john_doe
python slack_export.py --token xoxs-123... --directMessages jane_smith john_doe
# Export only Public/Private Channels and Group DMs (no 1:1 DMs)
python slack_export.py --token xoxs-123... --publicChannels --groups
# Export only 1:1 DMs with jane_smith and the Public Channels you select when prompted
python slack_export.py --token xoxs-123... --directMessages jane_smith --publicChannels --prompt
This script is provided in an as-is state and I guarantee no updates or quality of service at this time.
This is designed to function with 'slack-export-viewer'.
pip install slack-export-viewer
Then you can execute the viewer as documented
slack-export-viewer -z zipArchive.zip
slack-export-viewer <path_to_export_directory>