2022-04-27 00:02:50 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#Use ./gotifypush <title> <message> <priority> <token> <clickurl>
|
|
|
|
|
|
|
|
# Gotify notification parameters
|
|
|
|
TITLE=$1
|
|
|
|
MESSAGE=$2
|
|
|
|
PRIORITY=$3
|
2023-07-25 18:39:35 +02:00
|
|
|
URL="$E7S_GOTIFY_SERVER_URL/message?token=$4"
|
2022-04-27 00:02:50 +02:00
|
|
|
#if url passed by parameter, set to extras
|
|
|
|
if [ -n "$5" ]
|
|
|
|
then
|
|
|
|
EXTRAS="{\"client::display\": {\"contentType\": \"text/markdown\"}, \"client::notification\": {\"click\": { \"url\": \"$5\"}}}"
|
|
|
|
else
|
|
|
|
EXTRAS="{\"client::display\": {\"contentType\": \"text/markdown\"}}"
|
|
|
|
fi
|
|
|
|
|
2023-07-20 12:52:12 +02:00
|
|
|
# prevent gotify post error: invalid character '\\n' in string literal
|
|
|
|
# scape \\n newlines for json
|
|
|
|
# https://unix.stackexchange.com/questions/453883/how-to-escape-new-line-characters-for-json
|
2023-07-21 10:30:04 +02:00
|
|
|
# MESSAGE=$(echo "$MESSAGE" | sed -z 's/\n/\\n/g')
|
2023-07-20 12:52:12 +02:00
|
|
|
|
2022-04-27 00:02:50 +02:00
|
|
|
# better curl usage https://github.com/gotify/server/issues/68
|
|
|
|
#curl --silent --output /dev/null --show-error --fail -X .... #silent curl execution, no output, only html code if error
|
|
|
|
curl -X POST "${URL}" -H "accept: application/json" -H "Content-Type: application/json" -d "{ \"message\": \"${MESSAGE}\", \"priority\": ${PRIORITY}, \"title\": \"${TITLE}\", \"extras\": ${EXTRAS} }"
|