38 lines
820 B
Bash
Executable File
38 lines
820 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# send message to slack
|
|
#
|
|
# $1 message
|
|
# $2 username - optional
|
|
# $3 channel - optional
|
|
# $4 icon - optional
|
|
if [ "$1" = "" ]; then
|
|
echo "send message to slack"
|
|
echo "slackecho <message> [username] [channel] [icon]"
|
|
exit
|
|
fi
|
|
|
|
SLACKURL="https://hooks.slack.com/services/YOURURL"
|
|
|
|
#Setup defaults
|
|
if [ "$2" = "" ]; then
|
|
SLACKUSER="slackecho-user"
|
|
else
|
|
SLACKUSER="$2"
|
|
fi
|
|
|
|
if [ "$3" = "" ]; then
|
|
SLACKCH="general"
|
|
else
|
|
SLACKCH="$3"
|
|
fi
|
|
|
|
if [ "$4" = "" ]; then
|
|
SLACKICON=":robot_face:"
|
|
else
|
|
SLACKICON="$4"
|
|
fi
|
|
|
|
#build the post form and send it to the slack url
|
|
curl -X POST --data-urlencode 'payload={"channel": "#'$SLACKCH'", "username": "'$SLACKUSER'", "text": "'"$1"'", "icon_emoji": "'$SLACKICON'"}' $SLACKURL -o /dev/null >/dev/null 2>&1
|