#!/usr/bin/env bash # notify.sh — Telegram CI notifications. `source` this from other scripts. # # Provides: # notify_ok -> send a "success" notification # notify_fail -> 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 notify_ok() { local msg="$1" _notify_send "✅ Pangolin CI: ${msg}" } # notify_fail notify_fail() { local msg="$1" _notify_send "❌ Pangolin CI: ${msg}" }