-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack.sh
executable file
·77 lines (70 loc) · 1.76 KB
/
slack.sh
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
#: Title : Slack Integration
#: Date : 31-06-2015
#: Author : Francesco de Guytenaere <[email protected]>
#: Version : 1.0
#: Description : Simple wrapper for messaging through slack-integration
#: Options : -h help, -u url , -c channel, -n username, -i image, -t text
# Show help
usage="$(basename "$0") [-h] -- Simple tool to send messages to slack-integration using curl
usage:
-h Show this help text\n
-u Integration URL\n
-c Channel to send it to. Default is whatever you linked the integration to.\n
-n Username to send it as. Integration-Bot is default.\n
-i Image used as Avatar of the user. Default is :ghost:\n
-t Text to send
"
# Exit
die () {
echo >&2 "$@"
exit 1
}
# Check commandline arguments
while getopts 'u:c:n:i:t:h' opt; do
case "$opt" in
h) die "$usage"
;;
u) URL=$OPTARG
;;
c) CHANNEL=$OPTARG
;;
n) USERNAME=$OPTARG
;;
i) IMAGE=$OPTARG
;;
t) TEXT=$OPTARG
;;
\?) printf "illegal option: -%s\n" "$OPTARG" >&2
die "$usage"
;;
esac
done
shift $((OPTIND - 1))
# Check
if [[ -z $URL ]]; then
echo "$usage"
die "No integration url has been supplied."
fi
if [[ -z $USERNAME ]]; then
USERNAME=Integration-Bot
fi
if [[ -z $IMAGE ]]; then
IMAGE=:ghost:
fi
if [[ -z $TEXT ]]; then
echo "$usage"
die "No text has been supplied."
fi
# Send
curl \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
-X POST --data '
{
"channel": "'"$CHANNEL"'",
"username": "'"$USERNAME"'",
"text": "'"$TEXT"'",
"icon_emoji": "'"$IMAGE"'"
}' $URL
echo