Created
February 22, 2019 15:24
-
-
Save lewayotte/2633e63b7e02320a2d88c311313dd03b to your computer and use it in GitHub Desktop.
Mute specific Slack channels after hours, Unmute them during business hours...
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
<?php | |
// cronjob: | |
// 0 8 * * * /usr/bin/php /path/to/file.php unmute > /dev/null 2>&1 | |
// 0 18 * * * /usr/bin/php /path/to/file.php mute > /dev/null 2>&1 | |
if ( 1 < $argc ) { | |
$channels = array( | |
'CHANNEL_ID', | |
); | |
$after_hours_mute = array ( | |
'CHANNEL_ID', | |
); | |
if ( 'mute' == $argv['1'] ) { | |
$channels = array_merge( $channels, $after_hours_mute ); | |
} | |
mute( implode( ',', $channels ) ); | |
} | |
function mute( $channels ) { | |
$ch = curl_init( 'https://slack.com/api/users.prefs.set' ); | |
$data = http_build_query([ | |
'token' => 'YOUR_PERSONAL_TOKEN', // from: https://api.slack.com/custom-integrations/legacy-tokens | |
'prefs' => json_encode( array( 'muted_channels' => $channels ) ), | |
]); | |
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); | |
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data ); | |
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); | |
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); | |
$result = curl_exec( $ch ); | |
curl_close( $ch); | |
return $result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment