forked from ribot/dokku-slack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slack-notify
executable file
·34 lines (27 loc) · 918 Bytes
/
slack-notify
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
# Check we have a slack domain
if [ ! -n "$SLACK_DOMAIN" ]; then
echo 'Please specify the domain'; exit 1
fi
# Check we have a slack token
if [ ! -n "$SLACK_TOKEN" ]; then
echo 'Please specify a token'; exit 1
fi
# Check we have a valid channel (no # at the start)
if [ ! -n "$SLACK_CHANNEL" ]; then
echo 'Please specify a channel'; exit 1
fi
if [[ $SLACK_CHANNEL == \#* ]]; then
echo "Please specify the channel without the '#'"; exit 1
fi
# Read the message coming in from stdin
if [ -z "$INPUT" ]; then
MESSAGE=$(cat)
fi
# Build the JSON message
# TODO: Support coloring and attachments
JSON="{\"channel\": \"#$SLACK_CHANNEL\", \"text\": \"$MESSAGE\", \"username\": \"$SLACK_USERNAME\"}"
# Send the message
RESULT=`curl -s -d "payload=$JSON" "https://$SLACK_DOMAIN.slack.com/services/hooks/incoming-webhook?token=$SLACK_TOKEN" -w "%{http_code}"`
echo $RESULT
# TODO: Add error handling