about summary refs log tree commit diff
path: root/bundles/tgnotify/files
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2025-09-07 17:32:13 +0200
committerRobert Günzler <r@gnzler.io>2025-09-07 17:42:42 +0200
commit38be6c13f76e893cf47636257071b440dec0c5b2 (patch)
treef7ded3235a7e3362cbd1ed3d91523968fe0faf90 /bundles/tgnotify/files
initial commit
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'bundles/tgnotify/files')
-rwxr-xr-xbundles/tgnotify/files/tgnotify33
-rw-r--r--bundles/tgnotify/files/tgnotify.conf2
2 files changed, 35 insertions, 0 deletions
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")}