Table of Contents
This is an easy to use Slack App for downloading all messages in public channels of your Slack workspaces. This Slack App or Storage Bot as I like to call it, will store all messages in all public channels along with pertinent information such as timestamps and message sender. We accomplish this by utilizing Slack's SDK Bolt to extract conversation information and store them accordingly to a database of choice. You will need Admin access to add the Slack App to the Slack workspace.
-
Clone this repo and run
npm i
-
Create Slack App
-
Select "From an app manifest"
-
Pick the workspace you want to use storage -bot
-
Paste YAML code
Click to expand
display_information: name: storage features: bot_user: display_name: storage always_online: false oauth_config: scopes: bot: - app_mentions:read - channels:history - channels:read - chat:write - commands - im:history - im:read - im:write - users:read settings: event_subscriptions: bot_events: - message.im interactivity: is_enabled: true org_deploy_enabled: false socket_mode_enabled: true token_rotation_enabled: false
-
Create App
-
In "Basic Information", scroll down to "App-Level Tokens" and generate a token with scope "connections: write" and "authorization:read". You can name the token whatever you like - for example, test. Copy the generated token (starts with xapp)
-
Create a .env file at root and set APP_TOKEN = xapp token from the previous step.
-
Scroll up to "App Credentials". There will be a field called Signing Secret. Copy this token and in your .env file, set SLACK_SIGNING_SECRET = your Signing Secret.
-
Under "Settings", click on "Install App". Once installed, you will be given a Bot User OAuth Token. In your .env file, set SLACK_BOT_TOKEN = Bot User OAuth Token (this token starts with xoxb)
-
In the .env file set your URI = to the URI of whichever postgres you are using
Expand for PostgreSQL setup example using ElephantSQL
-
Invite Storage bot to the channels that you want to store the conversation histories of by using the slash command
/invite
in each of those channels
After you have setup the bot on Slack App, installed the Slack App into the workspace and setup the database, you can now run your bot. You will do this by messaging the bot (in this case storage bot) your commands. You will need to enter the following commands in order.
channel ids
- retrieves unique id of every public channel in Slack workspace and stores them in an array
channel names
- stores channel name, id and relevant information in channel table
user id
- stores user id information such as alias and timezone in userid table
all conversations
- stores all conversations in every channel that the bot is in and other information such as username, channel name and date in conversation table
conversation timestamp
- stores timestamp information for each conversation such as day, month, year, minute, sec, hour in timestamp table