#!/usr/bin/env bash set -e # Determine Icon based on Status ICON="🚀" if [ "$STATUS" = "failure" ]; then ICON="❌" fi # Prepare Text for Telegram (Markdown) TEXT="$ICON *$TITLE*%0A%0A$MESSAGE" echo "Starting notifications..." # Function: Send to Ntfy send_ntfy() { if [ -n "$NTFY_URL" ] && [ -n "$NTFY_TOPIC" ]; then local click_url="$GIT_URL/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}" local auth_args="" # Check for Basic Auth if [ -n "$NTFY_USERNAME" ] && [ -n "$NTFY_PASSWORD" ]; then auth_args="-u $NTFY_USERNAME:$NTFY_PASSWORD" fi echo "[Ntfy] Sending..." if curl -s $auth_args -X POST "$NTFY_URL/$NTFY_TOPIC" \ -H "Title: $ICON $TITLE" \ -H "Priority: 4" \ -H "Click: $click_url" \ -H "Actions: view, Open Logs, $click_url" \ -d "$MESSAGE"; then echo "[Ntfy] Sent." else echo "[Ntfy] Failed." fi fi } # Function: Send to Gmail send_gmail() { if [ -n "$GMAIL_USER" ] && [ -n "$GMAIL_TO" ] && [ -n "$GMAIL_PASS" ]; then if ! command -v sendmail &> /dev/null; then echo "[Gmail] Warning: sendmail not found, skipping." return fi echo "[Gmail] Sending..." { echo "Subject: $ICON $TITLE" echo "From: $GMAIL_USER" echo "To: $GMAIL_TO" echo "" echo "$MESSAGE" } | sendmail -S smtp.gmail.com:587 \ -au"$GMAIL_USER" \ -ap"$GMAIL_PASS" \ "$GMAIL_TO" && echo "[Gmail] Sent." || echo "[Gmail] Failed." fi } # Function: Send to Telegram send_telegram() { if [ -n "$TELEGRAM_BOT_TOKEN" ] && [ -n "$TELEGRAM_CHAT_ID" ]; then echo "[Telegram] Sending..." if curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \ -d chat_id="$TELEGRAM_CHAT_ID" \ -d parse_mode="Markdown" \ -d text="$TEXT"; then echo "[Telegram] Sent." else echo "[Telegram] Failed." fi fi } # Execute in parallel send_ntfy & PID_NTFY=$! send_gmail & PID_GMAIL=$! send_telegram & PID_TG=$! # Wait for completion wait $PID_NTFY wait $PID_GMAIL wait $PID_TG echo "All notifications processed."