Last active
December 5, 2017 03:49
-
-
Save zachleigh/6f1f1d1365ad9d3e1d5fd8e67660b404 to your computer and use it in GitHub Desktop.
Revisions
-
zachleigh revised this gist
Dec 5, 2017 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ class SlackFileDeleter * * @var string */ protected $domain = 'your Slack domain'; /** * Start time for delete. For example, if set to '-60 days' all files older -
zachleigh renamed this gist
Dec 5, 2017 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
zachleigh created this gist
Dec 5, 2017 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,74 @@ <?php use GuzzleHttp\Client; class SlackFileDeleter { /** * Slack API token. * * @var string */ protected $token = 'your api token'; /** * Slack domain. * * @var string */ protected $domain = 'your Slack domain; /** * Start time for delete. For example, if set to '-60 days' all files older * than 60 days will be deleted. * * @var string Valid strtotime string. */ protected $time = '-60 days'; /** * Clear the slack file backlog. */ public function cleanAction(array $params) { $data = [ 'token' => $this->token, 'ts_to' => strtotime($this->time), ]; $client = new Client(); $response = $client->request( 'post', 'https://slack.com/api/files.list', ['form_params' => $data] ); $files = json_decode($response->getBody(), true)['files']; if ($files != 0) { foreach ($files as $file) { echo "Deleting file {$file['name']} ..." . PHP_EOL; $timestamp = strtotime(time()); $delete_data = [ 'token' => $this->token, 'file' => $file['id'], 'set_active' => 'true', '_attempts' => 1, ]; $client = new Client(); $response = $client->request( 'post', "https://{$this->domain}.slack.com/api/files.delete?t={$timestamp}", ['form_params' => $delete_data] ); } echo "Done!" . PHP_EOL; } } }