From ac518353a9328cce9c08eefeb0c4e262b03fec79 Mon Sep 17 00:00:00 2001 From: Drew Short Date: Sun, 10 May 2020 15:50:29 -0500 Subject: [PATCH] Add configuration to format matrix messages as html --- README.md | 1 + bin/out | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/README.md b/README.md index 9ecb10f..216d160 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,7 @@ Send message to specified Matrix Room, with the configured parameters * `text`: (string) Text to send to the Matrix room as the content.body. * `text_file`: (string) File containing text to send to the Matrix room as the content.body. * `msgtype`: *Optional.* Message type, m.notice, m.text (default: m.notice) +* `is_html`: *Optional.* Indicate that the input is formatted as html * `data_file`: *Optional.* (string) Filename to post using a custom_event message type. If unset, defaults to the data_file on the resource. If it exists, the file must contain valid JSON. * `trigger`: *Optional.* (string) Arbitrary test to add to a "trigger" data item on custom message types. * `always_notify`: If true, send a notice even if text_file and data_file are empty. If false, and a text_file is specified but empty, a notification will not be sent. diff --git a/bin/out b/bin/out index e10472e..3fa6925 100755 --- a/bin/out +++ b/bin/out @@ -23,6 +23,7 @@ matrix_server_url="$(jq -r '.source.matrix_server_url' < "${payload}")" token="$(jq -r '.source.token' < "${payload}")" room_id="$(jq -r '.source.room_id' < "${payload}")" msgtype="$(jq -r '.source.msgtype // "m.notice"' < "${payload}")" +is_html="$(jq -r '.source.is_html // "false"' < "${payload}")" data_file="$(jq -r '.source.data_file // ""' < "${payload}")" ts="$(date +%s)" @@ -73,6 +74,10 @@ then text=$(echo -n "${text}" | jq -R -s .) [ -n "${formatted_body}" ] && formatted_body=$(echo -n "${formatted_body}" | jq -R -s .) + if [[ "${is_html}" = "true" ]]; then + formatted_body="${text}" + fi + [[ "${token}" != "null" ]] && username=$(echo "$token" | envsubst | jq -R -s .) [[ "${room_id}" != "null" ]] && room_id=$(echo "$room_id" | envsubst | jq -R -s .) body="$(cat <