2022-10-18 18:24:45 +02:00
|
|
|
{ lib
|
|
|
|
, writers
|
|
|
|
, curl
|
|
|
|
, jq
|
2020-10-20 01:11:28 +02:00
|
|
|
, homeserver
|
|
|
|
, roomId
|
|
|
|
, authToken
|
|
|
|
}:
|
|
|
|
|
2022-10-18 18:24:45 +02:00
|
|
|
writers.writeDashBin "notify" ''
|
|
|
|
export PATH="$PATH:${lib.makeBinPath [ curl jq ]}"
|
2020-10-20 01:11:28 +02:00
|
|
|
|
2022-10-18 18:24:45 +02:00
|
|
|
if test $(id -u) != 0; then
|
2020-10-20 01:11:28 +02:00
|
|
|
echo 'you must be root to send a notice'
|
|
|
|
exit 1
|
2022-10-18 18:24:45 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
token=$(cat ${authToken})
|
|
|
|
url="${homeserver}/rooms/${roomId}/send/m.room.message?access_token=$token"
|
|
|
|
|
|
|
|
if test $# -eq 1; then
|
|
|
|
# send first arg as text
|
|
|
|
msg=$(printf "%s" "$1" | jq -Rsc '{ "msgtype": "m.text", "body": . }')
|
|
|
|
else
|
|
|
|
# send stdin formatted as code
|
|
|
|
msg=$(jq -Rsc '{
|
|
|
|
"msgtype": "m.text",
|
|
|
|
"format": "org.matrix.custom.html",
|
|
|
|
"body": "",
|
|
|
|
"formatted_body": ("<pre><code>" + . + "</code></pre>")
|
|
|
|
}')
|
|
|
|
fi
|
2020-10-20 01:11:28 +02:00
|
|
|
|
2022-10-18 18:24:45 +02:00
|
|
|
curl -s "$url" -d "$msg"
|
2020-10-20 01:11:28 +02:00
|
|
|
''
|