Created
November 2, 2018 23:09
-
-
Save dishbreak/7d861d8b19804e4d93a6af3fff7e07d9 to your computer and use it in GitHub Desktop.
Send a message to a Slack Webhook
This file contains 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/bash | |
set -e | |
## Take in the Webhook URL from Slack and the actual message to send. | |
if [[ $# -ne 2 ]]; then | |
( >&2 echo "Usage $(basename "$0") WEBHOOK_URL MESSAGE" ) | |
exit 1 | |
fi | |
WEBHOOK_URL=$1 | |
MESSAGE=$2 | |
## Using a heredoc means you can type unescaped quotes, use interpolation and even whitespace to indent! | |
PAYLOAD=$(cat <<EOF | |
{"text": "$MESSAGE"} | |
EOF | |
) | |
# Flags used: | |
## --silent - no annoying progress bar. | |
## --request - the HTTP verb. | |
## --header - Never send JSON without saying it's JSON! | |
## --data - the body. | |
curl --silent \ | |
--request POST \ | |
--header "Content-Type: application/json" \ | |
--data "$PAYLOAD" \ | |
"$WEBHOOK_URL" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment