Mute specific Slack channels after hours, Unmute them during business hours...
This file contains 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