Skip to content

Instantly share code, notes, and snippets.

@hSATAC
Created October 23, 2014 06:35
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 hSATAC/35ac5041cefd92bed256 to your computer and use it in GitHub Desktop.
Save hSATAC/35ac5041cefd92bed256 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Usage: slackpost <username> <channel> <message>
# Enter the name of your slack host here - the thing that appears in your URL:
# https://slackhost.slack.com/
slackhost=HOST_HERE
token=TOKEN_HERE
userName=$1
if [[ $userName == "" ]]
then
echo "No username specified"
exit 1
fi
shift
channel=$1
if [[ $channel == "" ]]
then
echo "No channel specified"
exit 1
fi
shift
text=$*
if [[ $text == "" ]]
then
echo "No text specified"
exit 1
fi
escapedText=$(echo $text | sed 's/"/\"/g' | sed "s/'/\'/g" )
json="{\"channel\": \"#$channel\", \"text\": \"$escapedText\", \"username\": \"$userName\"}"
curl -s -d "payload=$json" "https://$slackhost.slack.com/services/hooks/incoming-webhook?token=$token"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment