Download & Backup Slack Chat History

Advertisement:

Slack has a new content deletion policy for free workspaces. As per the recent email from Slack in June 2024:

Workspaces’ data, including files, messages and other content that is older than one year will no longer be stored. Free workspaces will continue to have full access to the past 90 days of message history and file storage.

This policy will begin taking effect 26th August 2024. In my opinion, this is yet another way a product that was marketed as "free" to lure in users, has changed its course and left the users in a situation to either drop off or switch to a paid tier. While it makes sense from company's business point of view, I think it's kind of deceiving. Many not-for-profit initiatives, communities & groups switched to Slack but had no idea that this is all temporary.

slack-notification-about-free-tier-policy-change

I'm sceptical about Notion, Figma and many other 'free' applications for the same reason. You never know when they'll either switch to a paywall, preventing you from accessing your own data or get acquired by a bigger player that will try to impose its own strategies.

Quora did the same. Got in people to put in hours, days & months of efforts in answering questions, only to realise that all their efforts don't convert into free access to the information on the portal. Deceiving.

Anyway, in the context of Slack, while this policy change cannot be prevented (unless it gets a similar attention to what Adobe is getting for its AI change), there can still be something done to at least save the data one might have on Slack. Here's how:


Slack Data Backup

Slack Chat Backup

I've shared an open source script that allows you to create a custom Slack app for your workspace and download any chat data as a JSON. The code is available for free on my GitHub here: https://github.com/recreationdevelopers/Slack-Data-Backup

Script to backup a DM from a Slack subdomain. Use the code at your own risk and please do due diligence before running it.

Contact: If you're adding on to this script, please do let me know using the contact form here: prashantmishra.xyz/contact-me.html

Pre-Requisites

  1. You might require a Slack subscription (a 30-days trial will work) that grants you access to the entire message history. This code has been tested on a trial version of Slack Pro in June 2024.
  2. You need to have the necessary access to the Slack subdomain that should grant you permissions to create and install apps to your Slack Workspace. Please check with an admin before proceeding, if you aren't one.

Creating the Slack app

  1. Visit Slack API's app page and click on Create New App
    Slack App Page
  2. Choose From Scratch in the pop up that shows next.
    Slack App Create App
  3. Give the app an identifiable name and choose the workspace that the app should be associated with.
    Slack App Name and Workspace
  4. The click on Create App. This will take you to the settings section of the app.
    Slack OAuth and Permissions
  5. In the left panel, under the Features category, choose OAuth & Permissions.
  6. Scroll down to the Scopes section and under User Token Scopes, click on Add an OAuth Scope. This will show a dropdown with a list of possible permissions.
  7. Choose im:history and users:read permissions from this, one by one.
    Slack App Scopes
  8. Ensure that see you these added to the User Token Scopes section.
  9. Scroll up to the OAuth Tokens for Your Workspace section and click on Install to Workspace. This will take you to a permission-request page, where you can confirm the categories and click Allow.
    Slack App Granting Access
  10. You'll be taken back to the OAuth & Permissions page.
    Slack App User OAuth Token Example

Getting the Slack User Token:

  1. In the OAuth & Permissions page, scroll down to the OAuth Tokens for Your Workspace section.
  2. You should see a new User OAuth Token added. Click copy next to it so you can use this in the python script for the variable slack_user_token. Make sure to keep this token private.

Getting the Channel ID of the DM:

  1. Open the DM in Slack, preferably in a browser.
  2. In the URL, you’ll see something like (dummy url) https://app.slack.com/client/T12345678/D12345678
  3. Here D12345678 is the channel ID for the DM. Copy it so you can use it in python script's channel_id variable.

Python Script

The python file, downloadSlackDMToJSON.py has the following placeholders:

  • slack_user_token
  • channel_id
  • json_file_name - You can choose the name of the JSON file that will be created in the same directory.

Ensure that you have requests, json & optionally urllib3 python modules installed. If not, use pip to install them.

In case you're getting HTTPS warnings, you can uncomment the section in the code that uses urllib3.

Note:

  1. For files uploaded to the DM, you'll see url_private & url_private_download properties in the generated JSON. You can write another script to download them, although it can get tricky and might require additional bot token scopes or user token scopes permissions.
  2. Anytime you add an OAuth Scope to either Bot Token Scopes or User Token Scopes, you'll need to scroll up to the OAuth Tokens for Your Workspace section and click on Reinstall to Workspace for those permissions to come into effect.


Let me know if you use the script or found it helpful in the comment section below. Feel free to share this article / the GitHub repository for anyone who'll find it helpful.