From 758e4599ed336208c524c5ba4cb7af5f57dd9c1a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Wed, 16 Jun 2021 20:42:17 +0200 Subject: [PATCH] matrix-notifier: add markdown rendering w/ pandoc --- flake.nix | 1 + matrix-notifier | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 841883f..df25640 100644 --- a/flake.nix +++ b/flake.nix @@ -99,6 +99,7 @@ wrapperPath = with pkgs; lib.makeBinPath [ curl jq + pandoc ]; fixupPhase = '' diff --git a/matrix-notifier b/matrix-notifier index 22fca65..34a46b2 100755 --- a/matrix-notifier +++ b/matrix-notifier @@ -71,6 +71,15 @@ get_message_type() { printf '%s' "m.$MSG_TYPE" } +make_message_json() { + jq -s '.[0] * .[1]' \ + <(printf '%s' "$1" | + pandoc | + jq --raw-input --slurp "{format: \"org.matrix.custom.html\", formatted_body: .}") \ + <(printf '%s' "$1" | + jq --raw-input --slurp "{msgtype: \"$(get_message_type)\", body: .}") +} + send_message() { local login_json local token @@ -94,8 +103,7 @@ send_message() { exit 1 fi - message_json="$(printf '%s' "$MESSAGE" | - jq --raw-input --slurp "{msgtype: \"$(get_message_type)\", body: .}")" + message_json="$(make_message_json "$MESSAGE")" curl -XPOST \ -d "$message_json" \ "$ADDRESS/_matrix/client/r0/rooms/$(rawurlencode "$ROOM")/send/m.room.message?access_token=$(rawurlencode "$token")" 2>/dev/null