Last active
January 10, 2023 16:43
-
-
Save pr0PM/d72dd2471f527caecd9d3158fd85ac5d to your computer and use it in GitHub Desktop.
update slack status from cli
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 | |
set -euo pipefail | |
token="xoxp-yourtoken-goes-here-r4nd0m37r1ng" | |
# Instructions | |
# copy this anywhere, chmod +x path.sh | |
# set an alias on your fav shell rc | |
# eg: I moved it to ".local/bin/st" and now I can call it anywhere using just `st` | |
# ./local/bin being in my path | |
# dependency (to make stuf pretty) : | |
# gum: https://github.com/charmbracelet/gum | |
# | |
# Credits: https://github.com/mivok/slack_status_updater | |
# | |
# Steps to fetch token from Slack: | |
# Before you can use this, you need to add the status updater as a new slack app. To do this: | |
# Go to https://api.slack.com/apps/new to create a new app | |
# Choose a name for the new app: Slack status updater | |
# Select your workspace from the "Development Slack Workspace" dropdown | |
# This will bring you to the app configuration section, choose "OAuth and Permissions" from the sidebar on the left under the "Features" section. | |
# Scroll down until you see "User token scopes" and click "Add an OAuth scope" | |
# Type in users.profile:write and select it from the menu. | |
# If you want to use the awayback.sh script that's also in this repository, add the users:write scope as well. | |
# Scroll back to the top and click the "Install App to Workspace" button. | |
# You will be brought to a screen asking you to allow the app access. Click "Allow" | |
# You will be taken back to a screen containing an access token starting with xoxp-. Click the "Copy" button to copy this to the clipboard. | |
# st : Utility to update slack status | |
# commands | |
# cl - clear status | |
# brb [time] - should be back in [time(default 10)] mintutes [ 10, 15, 30 ] | |
# out - out for the day :pepe-bye: | |
# for rest of the day | |
# afk - should be back soon :afk-ooo: | |
# for 1h default | |
# break - snack break :pepesip: | |
# 30m default | |
#defaults | |
msg="" | |
emoji=":slack:" | |
def="" | |
set "${1:-$def}" | |
# set status as away/auto | |
function status () { | |
curl -s -o /dev/null --data "token=$token" --data presence="$1" https://slack.com/api/users.setPresence | |
} | |
now=$(date -u +%s) | |
# disable this if block if you want to skip using gum | |
if [ -n "$1" ]; then | |
cond=$1 | |
else | |
cond=$(gum choose "away" "cl" "brb" "out" "afk" "break" "ln" "back") | |
fi | |
case $cond in | |
"cl") | |
msg="" | |
emoji="" | |
expiry="0" | |
timeStamp="" | |
status "auto" | |
;; | |
"brb") | |
msg="brb" | |
emoji=":brb:" | |
expiry="15" | |
timeStamp=$((now + 60 * expiry)) | |
;; | |
"afk") | |
msg="afk" | |
emoji=":afk-ooo:" | |
expiry="60" | |
timeStamp=$((now + 60 * expiry)) | |
status "away" | |
;; | |
"break") | |
msg="snack break" | |
emoji=":pepesip:" | |
expiry="30" | |
timeStamp=$((now + 60 * expiry)) | |
status "away" | |
;; | |
"out") | |
msg="out for the day" | |
emoji=":pepe-bye:" | |
expiry="30" | |
timeStamp=$((now + 60 * expiry)) | |
status "away" | |
;; | |
"ln") | |
msg="lunch" | |
emoji=":shallow_pan_of_food:" | |
expiry="60" | |
timeStamp=$((now + 60 * expiry)) | |
status "away" | |
;; | |
"back") | |
status "auto" && exit 0 # exit to avoid changing existing status if any | |
;; | |
"away") | |
status "away" && exit 0 # via the api call at the end of case | |
;; | |
*) | |
# comment out this exit if you don't use gum | |
exit 0 | |
## same functionality as cl | |
# msg="" | |
# emoji="" | |
# expiry="0" | |
# timeStamp="" | |
# status "auto" | |
;; | |
esac | |
# payload | |
profile="{\"status_text\": \"$msg\", \"status_emoji\": \"$emoji\", \"status_expiration\": \"$timeStamp\"}" | |
# set status msg | |
curl -s -o /dev/null -X POST https://slack.com/api/users.profile.set --silent --data "profile=$profile" --data "token=$token" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment