Created
March 3, 2020 22:52
-
-
Save byrnereese/8deb6b81e687c967eaf1e52fedc8c30c to your computer and use it in GitHub Desktop.
A simple script to post a message to a Glip team via a "Glip Webhook URL"
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/sh | |
orig_args=$1 | |
OPTIND=1 | |
payload="" | |
needs_comma=false; | |
check_comma () | |
{ | |
if $needs_comma | |
then | |
payload="$payload," | |
fi | |
needs_comma=true; | |
} | |
show_help () | |
{ | |
echo "Usage:" | |
echo "$0 \"[title]\"" | |
echo "or" | |
echo "$0 -i 'icon_url [optional]' -a 'activity [optional]' -t 'title [optional]' -b 'body [optional]" | |
} | |
while getopts "h?i:a:t:b:" opt; do | |
case "$opt" in | |
h|\?) show_help && exit 0 | |
;; | |
i) check_comma && payload="$payload\"icon\":\"${OPTARG//\"/\\\"}\"" | |
;; | |
a) check_comma && payload="$payload\"activity\":\"${OPTARG//\"/\\\"}\"" | |
;; | |
t) check_comma && payload="$payload\"title\":\"${OPTARG//\"/\\\"}\"" | |
;; | |
b) check_comma && payload="$payload\"body\":\"${OPTARG//\"/\\\"}\"" | |
;; | |
esac | |
done | |
shift $((OPTIND-1)) | |
[ "$1" = "--" ] && shift; | |
if [ -z $payload ] | |
then | |
payload="\"title\":\"${orig_args//\"/\\\"}\"" | |
fi | |
curl -H 'Content-Type: application/json' -d "{$payload}" <ENTER URL HERE> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment