A Slack bot and standalone script for exporting messages and file attachments from public and private channels, using Slack's new Conversations API.
A similar service is provided by Slack for workspace admins at https://my.slack.com/services/export (where my
can be replaced with your full workspace name to refer to a workspace different than your default). However, it can only access public channels, while slack-exporter
can retrieve data from any channel accessible to your user account.
There are two ways to use slack-exporter
(detailed below). Both require a Slack API token to be able to communicate with your workspace.
- Visit https://api.slack.com/apps/ and sign in to your workspace.
- Click
Create New App
. If prompted to select "how you'd like to configure your app's scopes", choose theApp Manifest
option. You can configure the app manually instead, but you will be prompted to enter an app name and additional steps to set up permissions instead of the single step below. Once creates, select your workspace. - You should then be prompted for an app manifest. Paste the contents of the
slack.yaml
file (in the root of this repo) into the YAML box. - Select
Install to Workspace
at the top of that page (orReinstall to Workspace
if you have done this previously) and accept at the prompt. - Copy the
OAuth Access Token
(which will generally start withxoxp
for user-level permissions and may be located in a section like "OAuth & Permissions" in the sidebar).
exporter.py
can create an archive of all conversation history in your workspace which is accessible to your user account.
-
Either add
SLACK_USER_TOKEN = xoxp-xxxxxxxxxxxxx...
to a file named
.env
in the same directory asexporter.py
, or run the following in your shell (replacing the value with the user token you obtained in the Authentication with Slack section above).export SLACK_USER_TOKEN=xoxp-xxxxxxxxxxxxx...
-
If you cloned this repo, make sure that dependencies are installed by running
pip install -r requirements.txt
in the repo root directory. -
Run
python exporter.py --help
to view the available export options. You can test that access to Slack is working by listing available conversations:python exporter.py --lc
.
bot.py
is a Slack bot that responds to "slash commands" in Slack channels (e.g., /export-channel
). To connect the bot to the Slack app generated in Authentication with Slack, create a file named .env
in the root directory of this repo, and add the following line:
SLACK_USER_TOKEN = xoxp-xxxxxxxxxxxxx...
Save this file and run the Flask application in bot.py
such that the application is exposed to the Internet. This can be done via a web server (e.g., Heroku), as well as via the ngrok service, which assigns your localhost
server a public URL.
To use the ngrok method:
-
Download the appropriate binary.
-
Run
python bot.py
-
Run the ngrok binary with
path/to/ngrok http 5000
, where5000
is the port on which the Flask application (step 2) is running. Copy the forwarding HTTPS address provided. -
Create the following slash commands will be created (one for each applicable Flask route in
bot.py
):Command Request URL Arguments Example Usage /export-channel https:// [host_url]
/slack/export-channeljson | text /export-channel text /export-replies https:// [host_url]
/slack/export-repliesjson | text /export-replies json To do this, uncomment the
slash-commands
section inslack.yaml
and replaceYOUR_HOST_URL_HERE
with something likehttps://xxxxxxxxxxxx.ngrok.io
(if using ngrok). Then navigate back toOAuth & Permissions
and click(Re)install to Workspace
to add these slash commands to the workspace (ensure the OAuth token in your.env
file is still correct).
This software is available under the GPL.