Skip to content

Commit

Permalink
Add instructions on creating a slack app, add better error reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
mivok committed May 2, 2020
1 parent 9ff3070 commit 4f54ae2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
18 changes: 12 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
# Slack status updater

A simple shell script to update your status in slack from the command line,
based on presets you provide in a configuration file.
A simple shell script to update your status in slack from the command line, based on presets you provide in a configuration file.

## Installation

Copy `slack_status.sh` to somewhere in your path.

## Setup

First, you need to get an api token. Go to
<https://api.slack.com/custom-integrations/legacy-tokens> and grab the token
for your team. If you don't already have a token for your team, click the
'Create token' button next to the team to get a token.
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.
* 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.

Once you have the token, run `slack_status.sh setup` and follow the prompts.
This will create a configuration file for you.
Expand Down
20 changes: 11 additions & 9 deletions slack_status.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@ if [[ $1 == "setup" ]]; then
echo "${green}==========================${reset}"
echo
echo "You need to have your slack api token ready. If you don't have one,"
echo "go to https://api.slack.com/custom-integrations/legacy-tokens and"
echo "click 'Create token' for your team. This should give you a token"
echo "you can copy and paste here."
echo "go to https://github.com/mivok/slack_status_updater and follow the"
echo "instructions there for creating a new slack app."
echo
read -r -p "${green}Enter your slack token: ${reset}" TOKEN
cat > "$CONFIG_FILE" <<EOF
# vim: ft=sh
# Configuration file for slack_status
TOKEN=$TOKEN
PRESET_EMOJI_test=":check:"
PRESET_EMOJI_test=":white_check_mark:"
PRESET_TEXT_test="Testing status updater"
PRESET_EMOJI_zoom=":zoom:"
Expand Down Expand Up @@ -91,9 +90,12 @@ else
fi

PROFILE="{\"status_emoji\":\"$EMOJI\",\"status_text\":\"$TEXT\"}"
curl -s --data token="$TOKEN" \
RESPONSE=$(curl -s --data token="$TOKEN" \
--data-urlencode profile="$PROFILE" \
https://slack.com/api/users.profile.set | \
grep -q '"ok":true,' && \
echo "${green}Status updated ok${reset}" || \
echo "${red}There was a problem updating the status${reset}"
https://slack.com/api/users.profile.set)
if echo "$RESPONSE" | grep -q '"ok":true,'; then
echo "${green}Status updated ok${reset}"
else
echo "${red}There was a problem updating the status${reset}"
echo "Response: $RESPONSE"
fi

0 comments on commit 4f54ae2

Please sign in to comment.