Two scripts:
export_im.py exports all Slack instant messages into a directory called slack_dm_export. Files named dm_with_username.json for 121 chats and mpim_with_mpdm_username_username_username.json for multi-person.
export_channels.py exports all Slack channels into a directory called slack_channel_export. Files named channel_channelname.json.
In order for this to work, you need two things
- requests Python library
- a user token in Slack
To get the latter, follow these steps
- Create (or open) a Slack app
- Go to Slack API Apps: https://api.slack.com/apps
- open_in_new
- Click Create New App
- Choose From scratch
- Pick your app name and the workspace you want to install it to (Digital Library)
- Configure OAuth & Permissions (user scopes)
- In the left sidebar, go to OAuth & Permissions
- Scroll to Scopes
- Under User Token Scopes, click Add an OAuth Scope
- Add the user-level scopes you need (examples): -- users:read (read user info) -- im:read, im:history -- mpim:read, mpim:history -- channels:read, channels:history -- groups:read, groups:history
- If you instead add scopes under Bot Token Scopes, you’ll get a bot token (xoxb-...), not a user token (xoxp-...) and it won't work!
- Install the app to your workspace
- Still in OAuth & Permissions, click Install to (Workspace)
- Review the permissions screen
- Click Allow
- Copy the User OAuth Token After installation:
- Go back to OAuth & Permissions
- Look for OAuth Tokens for Your Workspace
- Copy the User OAuth Token (starts with xoxp-...)
- Copy the token into your scripts above ======= CONFIGURE YOUR TOKEN HERE ======= TOKEN = "" # DO NOT share publicly