Created
September 16, 2016 20:41
-
-
Save lgaticaq/8546b7ebc49ea6282f76c1662bb61b1b to your computer and use it in GitHub Desktop.
Send a simple message to slack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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