Add Telegram notification script for sending build artifacts

scripts/notify_telegram.sh sends a file (e.g. the debug APK) to a
Telegram chat via Bot API sendDocument. Reads TELEGRAM_BOT_TOKEN and
TELEGRAM_CHAT_ID from .telegram.env (gitignored, real credentials
never committed) or the environment. Verified end-to-end: sent the
current debug APK and confirmed delivery.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
vrubelroman 2026-07-09 20:17:07 +00:00
parent 0cc8d9b767
commit bb80307479
2 changed files with 46 additions and 0 deletions

37
scripts/notify_telegram.sh Executable file
View file

@ -0,0 +1,37 @@
#!/bin/sh
# Sends a file (e.g. a freshly built APK) to a Telegram chat via a bot.
# Usage: scripts/notify_telegram.sh <path-to-file> ["optional caption"]
#
# Reads TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID from .telegram.env
# (gitignored) at the repo root, or from the environment if already set.
set -eu
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
REPO_ROOT=$(cd "$SCRIPT_DIR/.." && pwd)
ENV_FILE="$REPO_ROOT/.telegram.env"
if [ -f "$ENV_FILE" ]; then
# shellcheck disable=SC1090
. "$ENV_FILE"
fi
if [ -z "${TELEGRAM_BOT_TOKEN:-}" ] || [ -z "${TELEGRAM_CHAT_ID:-}" ]; then
echo "TELEGRAM_BOT_TOKEN / TELEGRAM_CHAT_ID not set (checked $ENV_FILE and environment)." >&2
exit 1
fi
FILE_PATH="${1:?Usage: notify_telegram.sh <path-to-file> [caption]}"
CAPTION="${2:-$(basename "$FILE_PATH")}"
if [ ! -f "$FILE_PATH" ]; then
echo "File not found: $FILE_PATH" >&2
exit 1
fi
curl -sS -F "chat_id=${TELEGRAM_CHAT_ID}" \
-F "document=@${FILE_PATH}" \
-F "caption=${CAPTION}" \
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendDocument" \
| tee /dev/stderr \
| grep -q '"ok":true'