diff --git a/bin/out b/bin/out index 548530c..b0a8e3b 100755 --- a/bin/out +++ b/bin/out @@ -3,6 +3,13 @@ # Send message to a matrix room. API call looks like this: # curl -XPOST -d '{"msgtype":"m.text", "body":"hello"}' "http://matrix.org/_matrix/client/api/v1/rooms/%21CvcvRuDYDzTOzfKKgh%3Alocalhost/send/m.room.message?access_token=YOUR_ACCESS_TOKEN" +log () +{ + if [[ $1 == "debug" ]]; then + echo "DEBUG: $2" + fi +} + set -e # workaround for directory not existing before get in 3.0.0 mkdir -p "${1}" @@ -41,13 +48,14 @@ thismsgtype="$(jq -r '.params.msgtype // ""' < "${payload}")" [[ -n $thismsgtype && $thismsgtype != $msgtype ]] && msgtype="${thismsgtype}" always_notify="$(jq -r '.params.always_notify // "false"' < "${payload}")" -debug="$(jq -r '.params.debug // "false"' < "${payload}")" +debug="$(jq -r '.params.debug // ""' < "${payload}")" silent="$(jq -r '.params.silent // "true"' < "${payload}")" link="$(jq -r '.params.link // "false"' < "${payload}")" team="$(jq -r '.params.team // "main"' < "${payload}")" prefix="$(jq -r '.params.prefix // ""' < "${payload}")" is_html="$(jq -r '.params.is_html // "false"' < "${payload}")" +log("$debug", "$(jq '.' < "${payload}")") TEXT_FILE_CONTENT="" [[ -n "${text_file}" && ! -f "${text_file}" ]] && TEXT_FILE_CONTENT="_(text_file not found)_" @@ -66,15 +74,18 @@ then text=$(echo -en "${text}" | envsubst) [[ -z "${text}" ]] && text="_(missing notification text)_" + # If link is set, wrap the text in a link [ "${link}" == "true" ] && formatted_body="${text}" + # If prefix is set formatted_body if [ -n "$prefix" ]; then prefix=$(echo "$prefix" | envsubst) text="${prefix}: ${text}" [ -n "${formatted_body}" ] && formatted_body="${prefix}: ${formatted_body}" fi - if [[ "${is_html}" == "true" && -n "${formatted_body}" ]]; then + if [[ -z "${formatted_body}" && "${is_html}" == "true" ]]; then formatted_body="${text}" + log("$debug", "formatted_body=${formatted_body}") fi text=$(echo -n "${text}" | jq -R -s .) diff --git a/tag b/tag index 21e8796..ee90284 100644 --- a/tag +++ b/tag @@ -1 +1 @@ -1.0.3 +1.0.4