From bfe3a53ae409da49543046aa8eabc29264e4f6fe Mon Sep 17 00:00:00 2001 From: John Locke Date: Mon, 15 Aug 2016 11:13:17 -0700 Subject: [PATCH] Accept data_file and msgtype in either source or params -- if both set, params overrides source --- Dockerfile | 4 ++-- bin/out | 12 ++++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index f934e16..5e302ac 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM debian:jessie - -RUN apt-get update && apt-get -y install jq curl +RUN DEBIAN_FRONTENT=noninteractive && \ + apt-get update && apt-get -y install jq curl COPY bin/ /opt/resource/ RUN chmod +x /opt/resource/* diff --git a/bin/out b/bin/out index 18b28c0..81ca46f 100755 --- a/bin/out +++ b/bin/out @@ -21,20 +21,24 @@ cat > "${payload}" <&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}")" +msgtype="$(jq -r '.source.msgtype // "m.notice"' < "${payload}")" +data_file="$(jq -r '.source.data_file // ""' < "${payload}")" ts="$(date +%s)" matrix_endpoint="$matrix_server_url/_matrix/client/r0/rooms/$room_id/send/m.room.message/$ts?access_token=$token" text_file="$(jq -r '.params.text_file // ""' < "${payload}")" -data_file="$(jq -r '.params.data_file // ""' < "${payload}")" +thisdata_file="$(jq -r '.params.data_file // ""' < "${payload}")" +[ -n "$thisdata_file" && "$thisthisdata_file" != "$data_file" ] && data_file="${thisdata_file}" from="$(jq -r '.params.from // ""' < "${payload}")" text="$(jq '(.params.text // "${TEXT_FILE_CONTENT}")' < "${payload}")" -msgtype="$(jq '(.params.msgtype // "m.notice")' < "${payload}")" +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}")" -silent="$(jq -r '.params.silent // "false"' < "${payload}")" +silent="$(jq -r '.params.silent // "true"' < "${payload}")" TEXT_FILE_CONTENT="" [[ -n "${text_file}" && -f "${text_file}" ]] && TEXT_FILE_CONTENT="$(cat "${text_file}")" @@ -58,7 +62,7 @@ then } EOF )" - if [ "$msgtype" != "m.notice" ]; then + if [ "${msgtype}" != "m.notice" ]; then # we can attach custom data... builddata="$(cat <