Skip to content

Instantly share code, notes, and snippets.

@lgaticaq
Created September 16, 2016 20:41
Show Gist options
  • Save lgaticaq/8546b7ebc49ea6282f76c1662bb61b1b to your computer and use it in GitHub Desktop.
Save lgaticaq/8546b7ebc49ea6282f76c1662bb61b1b to your computer and use it in GitHub Desktop.
Send a simple message to slack
#!/bin/sh
# Usage: send-to-slack <channel> <text>
# Example: send-to-slack random Hello world
# Set your slack token and domain with:
# export SLACK_TOKEN=your-slack-token
# export SLACK_USERNAME=some-username
if [[ $SLACK_TOKEN == "" ]]
then
echo "No token specified"
exit 1
fi
CHANNEL=$1
if [[ $CHANNEL == "" ]]
then
echo "No channel specified"
exit 1
fi
shift
TEXT=$*
if [[ $TEXT == "" ]]
then
echo "No text specified"
exit 1
fi
if [[ $SLACK_USERNAME == "" ]]
then
SLACK_USERNAME=bot
fi
curl -X POST -F "channel=#${CHANNEL}" -F "username=${SLACK_USERNAME}" -F "text=${TEXT}" -F "token=${SLACK_TOKEN}" https://api.slack.com/api/chat.postMessage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment