From 38be6c13f76e893cf47636257071b440dec0c5b2 Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Sun, 7 Sep 2025 17:32:13 +0200 Subject: initial commit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- bundles/tgnotify/files/tgnotify | 33 +++++++++++++++++++++++++++++++++ bundles/tgnotify/files/tgnotify.conf | 2 ++ 2 files changed, 35 insertions(+) create mode 100755 bundles/tgnotify/files/tgnotify create mode 100644 bundles/tgnotify/files/tgnotify.conf (limited to 'bundles/tgnotify/files') diff --git a/bundles/tgnotify/files/tgnotify b/bundles/tgnotify/files/tgnotify new file mode 100755 index 0000000..44dd85d --- /dev/null +++ b/bundles/tgnotify/files/tgnotify @@ -0,0 +1,33 @@ +#!/bin/sh +set -eu + +# import environment from config +# can overwrite above defaults +set -a +. /etc/tgnotify.conf || true +set +a + +# fail if token or chatid are missing +tg_bot_token=${TG_BOT_TOKEN:?} +tg_chat_id=${TG_CHAT_ID:?} + +main() { + local tg_msg + local tg_curl_args="-sS -o /dev/null" + + if [ "$1" = "-" ]; then + while read -r ln; do tg_msg="${tg_msg}%0A${ln}"; done + else + tg_msg=$(printf '%s' "$*" | sed -e 's,\\n,%0A,g') + fi + + test -n "${DEBUG:-}" && tg_curl_args="-v -o /dev/stdout" + test -n "${DEBUG:-}" && set -x + + exec curl ${tg_curl_args} \ + -d "chat_id=${tg_chat_id}&disable_notification=false&disable_web_page_preview=true&parse_mode=markdown&text=${tg_msg}" \ + -H "Content-Type: application/x-www-form-urlencoded" \ + "https://api.telegram.org/bot${tg_bot_token}/sendMessage" +} + +main "$@" diff --git a/bundles/tgnotify/files/tgnotify.conf b/bundles/tgnotify/files/tgnotify.conf new file mode 100644 index 0000000..040c2fc --- /dev/null +++ b/bundles/tgnotify/files/tgnotify.conf @@ -0,0 +1,2 @@ +TG_BOT_TOKEN=${repo.vault.cmd(f"rbw get tgnotify/token")} +TG_CHAT_ID=${repo.vault.cmd(f"rbw get tgnotify/chatid")} -- cgit 1.4.1