Skip to content

Instantly share code, notes, and snippets.

@chrislopresto
Last active January 3, 2016 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrislopresto/8442674 to your computer and use it in GitHub Desktop.
Save chrislopresto/8442674 to your computer and use it in GitHub Desktop.
A bash executable with command line options to post into slack channels
#!/bin/bash
# A convenient way to post to Slack channels from the command line... as Lionel Richie
#
# Usage
# ./slack_message
# ./slack_message -t "Hello..."
# ./slack_message -i https://pbs.twimg.com/profile_images/421128111086764032/zv1APHT5.jpeg -u justin -t "I'll be your platinum, I'll be your silver, I'll be your gold"
TOKEN='YOUR_TOKEN_GOES_HERE'
SUBDOMAIN='YOUR_SUBDOMAIN_GOES_HERE'
ENDPOINT="https://$SUBDOMAIN.slack.com/services/hooks/incoming-webhook?token=$TOKEN"
USERNAME='lionel'
CHANNEL='#general'
TEXT="Hello... is it me you're looking for?"
ICON_URL='https://pbs.twimg.com/profile_images/378800000712297666/1b78a729761feed16a2c571a8c390743.jpeg'
ICON_EMOJI=':ghost:'
while getopts "t:c:u:i:" OPTION; do
case $OPTION in
t) TEXT=$OPTARG ;;
c) CHANNEL=$OPTARG ;;
u) USERNAME=$OPTARG ;;
i) ICON_URL=$OPTARG ;;
esac
done
curl \
-X POST \
--data "payload={\"channel\": \"$CHANNEL\", \"username\": \"$USERNAME\", \"text\": \"$TEXT\", \"icon_url\": \"$ICON_URL\"}" \
"$ENDPOINT"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment