diff --git a/bin/out b/bin/out index 8e9e72c..b37fb5e 100755 --- a/bin/out +++ b/bin/out @@ -3,7 +3,6 @@ # 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" - set -e # workaround for directory not existing before get in 3.0.0 mkdir -p "${1}" @@ -19,6 +18,8 @@ payload=$(mktemp /tmp/resource-in.XXXXXX) cat > "${payload}" <&0 +echo "Matrix-Notification-Resource Version: 1.0.0" + matrix_server_url="$(jq -r '.source.matrix_server_url' < "${payload}")" token="$(jq -r '.source.token' < "${payload}")" room_id="$(jq -r '.source.room_id' < "${payload}")" @@ -71,13 +72,13 @@ then [ -n "${formatted_body}" ] && formatted_body="${prefix}: ${formatted_body}" fi - text=$(echo -n "${text}" | jq -R -s .) - [ -n "${formatted_body}" ] && formatted_body=$(echo -n "${formatted_body}" | jq -R -s .) - - if [[ "${is_html}" == "true" ]]; then + if [[ "${is_html}" == "true" && -n "${formatted_body}" ]]; then formatted_body="${text}" fi + text=$(echo -n "${text}" | jq -R -s .) + [ -n "${formatted_body}" ] && formatted_body=$(echo -n "${formatted_body}" | jq -R -s .) + [[ "${token}" != "null" ]] && username=$(echo "$token" | envsubst | jq -R -s .) [[ "${room_id}" != "null" ]] && room_id=$(echo "$room_id" | envsubst | jq -R -s .) body="$(cat <