-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathslack-webhook-send-message
executable file
·59 lines (56 loc) · 1.37 KB
/
slack-webhook-send-message
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
#!/bin/bash
set -euf -o pipefail
##
# Slack.com script that uses a webhook to send a message.
#
# Syntax:
#
# slack-webhook-send-message <url> <channel> <username> <text>
#
# Example:
#
# slack-webhook-send-message
# https://hooks.slack.com/services/mykey
# myusername
# myemoji
# mychannel
# "Hello World"
#
# This script uses our preferred conventions:
#
# * It requires parameters for a user name, emoji, and channel.
# * It logs to syslog.
#
# ## Environment Variables
#
# This script can use environment variables for command paths:
#
# * CURL: `curl` command. Example: `CURL=/usr/bin/curl`
#
# This script can use environment variables for parameter defaults:
#
# * SLACK_HOOK
# * SLACK_USERNAME
# * SLACK_EMOJI
# * SLACK_CHANNEL
# * SLACK_TEXT
#
# ## Future Ideas
#
# Change from positional parameters to key=val parameters.
#
# ## Contact
#
# Contact: Joel Parker Henderson ([email protected])
# License: GPL
# Created: 2015-09-19
# Updated: 2015-09-21
# Version: 1.1
##
hook="${1:-$SLACK_HOOK}"
username="${2:-$SLACK_USERNAME}"
emoji="${3:-$SLACK_EMOJI}"
channel="${4:-$SLACK_CHANNEL}"
text="${5:-$SLACK_TEXT}"
logger "$0 $hook $username $emoji $channel $text"
${CURL:-curl} -X POST "$hook" --data-urlencode "payload={\"username\": \"$username\", \"icon_emoji\": \"$emoji\", \"channel\": \"$channel\", \"text\": \"$text\"}"