Skip to content

Instantly share code, notes, and snippets.

@aroyrev
Forked from mattak/slackpost.sh
Created April 26, 2019 00:19
Show Gist options
  • Select an option

  • Save aroyrev/3f1e4c4ea05156d33932c9455d39b829 to your computer and use it in GitHub Desktop.

Select an option

Save aroyrev/3f1e4c4ea05156d33932c9455d39b829 to your computer and use it in GitHub Desktop.
post message to slack
#!bash -e
TOKEN=
CHANNEL=
MESSAGE=
NICK=
# base info
AUTH_RESPONSE=$(curl https://slack.com/api/auth.test)
TEAM=$(echo $AUTH_RESPONSE | jq '.team')
TEAM_ID=$(echo $AUTH_RESPONSE | jq '.team_id')
USER_ID=$(echo $AUTH_RESPONSE | jq '.user_id')
URL=$(echo $AUTH_RESPONSE | jq '.url')
USER=$(echo $AUTH_RESPONSE | jq '.user')
# channel info
CHANNELS_RESPONSE=$(curl "https://slack.com/api/groups.list?token=$TOKEN")
CHANNEL_ID=$(echo $CHANNELS_RESPONSE | jq '.groups[]' | jq "if .name == \"$CHANNEL\" then .id else null end" -M -c -r | grep -v null)
# post message
curl -X POST \
-F token=$TOKEN \
-F channel=$CHANNEL_ID \
-F "text=$MESSAGE" \
-F username=$NICK \
https://slack.com/api/chat.postMessage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment