ruby 这个Ruby脚本将批量删除超过30天的所有Slack文件。只需从https://api.slack.com/web#authentication添加您的API令牌即可
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ruby 这个Ruby脚本将批量删除超过30天的所有Slack文件。只需从https://api.slack.com/web#authentication添加您的API令牌即可相关的知识,希望对你有一定的参考价值。
require 'net/http'
require 'json'
require 'uri'
@token = ''
def list_files
ts_to = (Time.now - 30 * 24 * 60 * 60).to_i # 30 days ago
params = {
token: @token,
ts_to: ts_to,
count: 1000
}
uri = URI.parse('https://slack.com/api/files.list')
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get_response(uri)
JSON.parse(response.body)['files']
end
def delete_files(file_ids)
file_ids.each do |file_id|
params = {
token: @token,
file: file_id
}
uri = URI.parse('https://slack.com/api/files.delete')
uri.query = URI.encode_www_form(params)
response = Net::HTTP.get_response(uri)
p "#{file_id}: #{JSON.parse(response.body)['ok']}"
end
end
p 'Deleting files...'
files = list_files
file_ids = files.map { |f| f['id'] }
delete_files(file_ids)
p 'Done!'
以上是关于ruby 这个Ruby脚本将批量删除超过30天的所有Slack文件。只需从https://api.slack.com/web#authentication添加您的API令牌即可的主要内容,如果未能解决你的问题,请参考以下文章