Skip to content

Instantly share code, notes, and snippets.

@reneweteling
Last active September 26, 2017 14:25
Show Gist options
  • Save reneweteling/c3deca29af1b76e0a16c5dc85ecbd76f to your computer and use it in GitHub Desktop.
Save reneweteling/c3deca29af1b76e0a16c5dc85ecbd76f to your computer and use it in GitHub Desktop.
Bulk remove slack files older than 1 month
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
@reneweteling
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment