Last active
July 28, 2016 15:02
-
-
Save holysugar/08a8fd33aaa24be5be8e246b17631796 to your computer and use it in GitHub Desktop.
slacksay
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 | |
# set ft=sh | |
set -e | |
# available variables: | |
# | |
# SLACKSAY_WEBHOOKURL | |
# SLACKSAY_CHANNEL | |
# SLACKSAY_USERNAME | |
# SLACKSAY_ICON_EMOJI | |
SLACKSAY_CHANNEL=${SLACKSAY_CHANNEL:-'#bot-test'} | |
SLACKSAY_USERNAME=${SLACKSAY_USERNAME:-'slacksay'} | |
SLACKSAY_ICON_EMOJI=${SLACKSAY_ICON_EMOJI:-':ghost:'} | |
while getopts pvq opt | |
do | |
case $opt in | |
p) | |
SLACKSAY_PRE=1 | |
;; | |
v) | |
SLACKSAY_CURL_OPTION='-v' | |
;; | |
q) | |
SLACKSAY_QUIET=1 | |
;; | |
esac | |
done | |
if [ -z "$SLACKSAY_WEBHOOKURL" ]; then | |
if [ -z "$SLACKSAY_QUIET" ]; then | |
echo 'set $WEBHOOKURL to access Slack.' | |
fi | |
exit 1 | |
fi | |
message=$(sed -e 's/"/\\"/g') | |
if [ -n "$SLACKSAY_PRE" ]; then | |
message="\`\`\`${message}\`\`\`" | |
fi | |
curl $SLACKSAY_CURL_OPTION -s -S -X POST --data-urlencode \ | |
'payload={"channel":"'$SLACKSAY_CHANNEL'", "username": "'$SLACKSAY_USERNAME'", | |
"icon_emoji": "'$SLACKSAY_ICON_EMOJI'", "text": "'"$message"'"} ' $SLACKSAY_WEBHOOKURL | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment