diff options
Diffstat (limited to 'bundles/tgnotify/files')
| -rwxr-xr-x | bundles/tgnotify/files/tgnotify | 33 | ||||
| -rw-r--r-- | bundles/tgnotify/files/tgnotify.conf | 2 |
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")} |