Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
Created November 21, 2022 16:22
Show Gist options
  • Save georgestephanis/ade72ae58e75066b69c63a7ab5cc8507 to your computer and use it in GitHub Desktop.
Save georgestephanis/ade72ae58e75066b69c63a7ab5cc8507 to your computer and use it in GitHub Desktop.
don't forget to add in the bearer token on line 23
<?php
function set_myself_afk() {
$tz = date('I') ? 'EST' : 'EDT';
$expiration = strtotime( "+1 Weekday 9am {$tz}" );
$weekday = array(
'status_text' => 'AFK for the evening.',
'status_emoji' => ':family:',
'status_expiration' => $expiration,
);
$weekend = array(
'status_text' => 'AFK for the weekend.',
'status_emoji' => ':weekend-2:',
'status_expiration' => $expiration,
);
$opts = array(
'http' => array(
'method' => 'POST',
'header' => array(
'Authorization: Bearer TOKEN_GOES_HERE',
'Content-Type: application/json',
),
'content' => json_encode(
array(
'profile' => ( 5 <= (int) date( 'w' ) ) ? $weekend : $weekday,
)
),
),
);
$contents = file_get_contents(
'https://slack.com/api/users.profile.set',
false,
stream_context_create( $opts )
);
return $contents;
}
set_myself_afk();
@georgestephanis
Copy link
Author

The crontab entry I use to fire this at 3:30pm on Weekdays for me is --

30 15 * * 1-5 /usr/local/bin/php /the/path/to/slack-afk-automator.php >/dev/null 2>&1

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