Last active
September 26, 2017 14:25
-
-
Save reneweteling/c3deca29af1b76e0a16c5dc85ecbd76f to your computer and use it in GitHub Desktop.
Bulk remove slack files older than 1 month
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :slack do | |
task :dropfiles do | |
token = 'xoxp-?????' # h&f | |
# get upser id | |
user_id = 'U02B4AR0N' | |
# get files | |
cmd = "curl -s -X POST --data '#{{token: token, count: 1000, user: user_id}.to_query}' https://slack.com/api/files.list" | |
files = run_slack_cmd(cmd)['files'] | |
# delete files older than 2 months | |
files.each do |f| | |
if Time.at(f['created']) < Date.today - 2.months | |
data = { | |
token: token, | |
file: f['id'] | |
} | |
cmd = "curl -s -X POST --data '#{data.to_query}' https://slack.com/api/files.delete" | |
pp run_slack_cmd(cmd) | |
end | |
end | |
end | |
def run_slack_cmd cmd | |
JSON.parse(`#{cmd}`) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go to:
https://my.slack.com/files
click on my files, than youll see your user_id in the url bar
go to https://api.slack.com/custom-integrations/legacy-tokens and generate a token for your channel and run it