This repository has been archived by the owner on May 1, 2024. It is now read-only.
/
config.slack.yaml
57 lines (50 loc) · 1.84 KB
/
config.slack.yaml
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
# This example shows how you can send a Slack message using Slack webhooks.
# Slack docs: https://slack.com/intl/en-fi/help/articles/115005265063-Incoming-webhooks-for-Slack
#
# Test with:
#
# curl "http://localhost:7055/slack/world"
#
# All logging enabled
debug: true
listeners:
# The route
/slack/:name:
env:
# If the program is run with the SLACK_HOOK environment
# variable set, it will use that one, otherwise use the provided
# string.
SLACK_HOOK: '{{ coalesce (env "SLACK_HOOK") "https://hooks.slack.com/services/XXXXXXXX" }}'
# For cleanliness and readability, save the Slack payload in a tmp YAML file,
# which will be converted to JSON later.
files:
payload.yaml: |
username: Test Slack hook from QV!
icon_emoji: ":jack_o_lantern:"
text: |
Hello {{ .name }}!
# Command to run, and list of arguments
command: bash
args:
- -c
# When executing bash commands, we need to set -e to propagate any errors.
- -e
- |
# Send the request, converting the YAML file into a JSON one on the fly, and
# expect HTTP 200 code
STATUS=$(curl -s -o /dev/stderr --write-out "%{http_code}" \
-X POST -H "Content-Type: application/json" "$SLACK_HOOK" --data-binary @- << EOF
{{ fileReadToString (qv).files.payload_yaml | yamlToJson }}
EOF
)
echo "Status: $STATUS"
# Our command should succeed ONLY if we got a 200 code.
# This will cause the script to exit with an error if
# we have not gotten the proper status code.
[ $STATUS -eq 200 ]
plugins:
# We initialize the retry plugin, and configure it to retry if we have been rate-limited
- retry:
condition: |
contains "Status: 429" .__qvRetry.PreviousResult.Output
delay: "5s"