Files
2026-07-05 23:49:59 +08:00

37 lines
1.2 KiB
Bash
Executable File

#!/usr/bin/env bash
# notify.sh — Telegram CI notifications. `source` this from other scripts.
#
# Provides:
# notify_ok <msg> -> send a "success" notification
# notify_fail <msg> -> send a "failure" notification
#
# Uses the same TELEGRAM_BOT_TOKEN / TELEGRAM_CHAT_ID convention as
# deploy/bootstrap/monitor/pangolin-monitor.sh. Safe no-op (never fails the
# pipeline) when those are unset, or when the Telegram API call itself fails.
_notify_send() {
local text="$1"
if [ -z "${TELEGRAM_BOT_TOKEN:-}" ] || [ -z "${TELEGRAM_CHAT_ID:-}" ]; then
echo "==> notify: (skipped, no TELEGRAM_BOT_TOKEN/TELEGRAM_CHAT_ID) ${text}"
return 0
fi
curl -fsS --max-time 15 \
"https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
--data-urlencode "chat_id=${TELEGRAM_CHAT_ID}" \
--data-urlencode "text=${text}" \
--data "disable_web_page_preview=true" >/dev/null 2>&1 \
|| echo "==> notify: Telegram 发送失败(已忽略,不影响流水线)" >&2
}
# notify_ok <msg>
notify_ok() {
local msg="$1"
_notify_send "✅ Pangolin CI: ${msg}"
}
# notify_fail <msg>
notify_fail() {
local msg="$1"
_notify_send "❌ Pangolin CI: ${msg}"
}