-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathslacker.cfg
57 lines (49 loc) · 1.3 KB
/
slacker.cfg
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
[buildout]
parts += slacker
# slack-webhook = https://hooks.slack.com/services/111/222/333
#=> https://my.slack.com/services/new/incoming-webhook/
[slacker]
recipe = collective.recipe.template
output = ${buildout:directory}/bin/slacker
mode = 755
input = inline:
#!/usr/bin/env sh
URL="${buildout:slack-webhook}"
OPTIND=1
text=""
channel=""
username=""
icon=""
raw=0
readstdin=0
while getopts "h?t:c:u:i:rs" opt; do
case "$opt" in
h|\?)
echo "USAGE: slacker [-t TEXT] [-c CHANNEL] [-u USERNAME] [-i ICON] [-h] [-r] [-s]"
exit 0
;;
t) text=$OPTARG
;;
c) channel=$OPTARG
;;
u) username=$OPTARG
;;
i) icon=$OPTARG
;;
r) raw=1
;;
s) readstdin=1
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
if [ $readstdin -eq 1 ]; then
text=`cat`
fi
if [ $raw -eq 1 ]; then
data="$text"
else
data="{\"text\": \"$text\", \"channel\": \"$channel\", \"username\": \"$username\", \"icon_emoji\": \"$icon\"}"
fi
curl -X POST -H 'Content-type: application/json' --data "$data" $URL