matrix-notifier: add markdown rendering w/ pandoc

This commit is contained in:
Bruno BELANYI 2021-06-16 20:42:17 +02:00
parent 75d482cd6b
commit 758e4599ed
2 changed files with 11 additions and 2 deletions

View file

@ -99,6 +99,7 @@
wrapperPath = with pkgs; lib.makeBinPath [
curl
jq
pandoc
];
fixupPhase = ''

View file

@ -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