Last active
April 14, 2017 15:28
-
-
Save MarcBernstein/bbbf099a87ae21643590078da777d554 to your computer and use it in GitHub Desktop.
Sets Slack status using new Status API. Save the script somewhere in your $PATH and set it executable.
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
#!/bin/bash | |
# Sets Slack status using new Status API. | |
# Save the script somewhere in your $PATH and set it executable. | |
slacktoken=<Your auth token, get one here https://api.slack.com/custom-integrations/legacy-tokens> | |
apiurl="https://slack.com/api/users.profile.set?token="$slacktoken"&profile=" | |
if ! [ $# -eq 0 ] && ! [ $# -eq 2 ]; then | |
echo "Script takes exactly 0 (remove status ) or 2 arguments (emoji and status (in quotes if more than one word))."; | |
exit 1; | |
fi | |
if [ $# -eq 0 ] | |
then | |
status="\"status_text\": \"\", \"status_emoji\": \"\"" | |
else | |
case $1 in | |
:*:) | |
emoji="$1";; | |
*) | |
emoji=":$1:";; | |
esac | |
status="\"status_text\": \"$2\", \"status_emoji\": \"${emoji}\"" | |
fi | |
response=$(curl --silent --data-urlencode "profile={$status}" $apiurl) | |
if ! [[ $response =~ \"ok\":true ]]; then | |
echo "Setting status failed, check that emoji is valid?"; | |
echo "Response was: $response" | |
exit 1; | |
else | |
if [ $# -eq 0 ]; then | |
echo "Status is unset." | |
else | |
echo "Status set to $2, emoji is $emoji" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment