From 11bf454409a3c0209512b45d5798d946783f9fc4 Mon Sep 17 00:00:00 2001 From: John Locke Date: Mon, 15 Aug 2016 09:45:17 -0700 Subject: [PATCH] Add support for params.data_file, source.msgtype, and params.msgtype --- README.md | 16 +++++++++++++--- bin/out | 35 ++++++++++++++++++++++------------- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index ecf7d1b..b82f0df 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,9 @@ Then, a user will need to invite the account to the appropriate room, and the ac * `matrix_server_url`: *Required.* Example: https://matrix.org * `token`: *Required.* token to authenticate with Matrix server * `room_id`: *Required.* The room to send notifications to -- this account must already be a member of this room. +* `msgtype`: Used to post a custom message type e.g. if you want to attach a json blob. If set to anything other than m.notice, the resource will attach a "build" json object containing the build metadata info. Defaults to `m.notice`, can be overridden by the put resource. +* `data_file`: *Optional.* (string) Default file to post to the data key of a custom message type. The contents of this file is generally assumed to be a JSON-encoded string. Can be overridden in the job parameters. + Pull requests accepted for room_alias, user logins, auto-joins. @@ -47,13 +50,15 @@ Pull requests accepted for room_alias, user logins, auto-joins. Send message to specified Matrix Room, with the configured parameters #### Parameters -* `text`: (string) Text to send to the Matrix room -* `text_file`: (string) File containing text to send to the Matrix room +* `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) +* `data_file`: *Optional.* (string) Filename to post using a custom_event message type. If unset, defaults to the data_file on the resource. +* `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. ## Example -### Check +### Resources ``` --- resources: @@ -63,8 +68,13 @@ resources: matrix_server_url: https://matrix.org token: {{matrix_token}} room_id: {{matrix_room_id}} + data_file: data ``` +### Check + +*Not supported* + ### In *Not supported* diff --git a/bin/out b/bin/out index 26dd131..e496a97 100755 --- a/bin/out +++ b/bin/out @@ -27,6 +27,7 @@ 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}")" from="$(jq -r '.params.from // ""' < "${payload}")" text="$(jq '(.params.text // "${TEXT_FILE_CONTENT}")' < "${payload}")" msgtype="$(jq '(.params.msgtype // "m.notice")' < "${payload}")" @@ -37,8 +38,10 @@ silent="$(jq -r '.params.silent // "false"' < "${payload}")" TEXT_FILE_CONTENT="" [[ -n "${text_file}" && -f "${text_file}" ]] && TEXT_FILE_CONTENT="$(cat "${text_file}")" +DATA_FILE_CONTENT="" +[[ -n "${data_file}" && -f "${data_file}" ]] && DATA_FILE_CONTENT="$(cat "${data_file}")" -if [[ "$always_notify" == "true" || -n "$TEXT_FILE_CONTENT" || -z "$text_file" ]] +if [[ "$always_notify" == "true" || -n "$TEXT_FILE_CONTENT" || -z "$text_file" || -n "$DATA_FILE_CONTENT" ]] then TEXT_FILE_CONTENT="${TEXT_FILE_CONTENT:-_(no notification provided)_}" @@ -55,21 +58,27 @@ then } EOF )" - - compact_body="$(echo "${body}" | jq -c '.')" - - if [[ "$debug" == "true" ]] - then - json="$(cat <