opt: moderm message

This commit is contained in:
2025-12-30 13:50:34 +07:00
parent 783b920fa4
commit c047741832

View File

@@ -15,10 +15,19 @@ echo ""
# Function: Send to Ntfy (Modern Push Notification) # Function: Send to Ntfy (Modern Push Notification)
send_ntfy() { send_ntfy() {
if [ -n "$NTFY_URL" ] && [ -n "$NTFY_TOPIC" ]; then
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
echo -e "${YELLOW}🔔 Ntfy Push Notification${NC}" echo -e "${YELLOW}🔔 Ntfy Push Notification${NC}"
echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}" echo -e "${YELLOW}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${NC}"
# Debug: Show environment variables
echo -e " ${YELLOW}Debug Info:${NC}"
echo -e " NTFY_URL: ${GREEN}${NTFY_URL:-'(not set)'}${NC}"
echo -e " NTFY_TOPIC: ${GREEN}${NTFY_TOPIC:-'(not set)'}${NC}"
echo -e " NTFY_USERNAME: ${GREEN}${NTFY_USERNAME:-'(not set)'}${NC}"
echo -e " NTFY_PASSWORD: ${GREEN}${NTFY_PASSWORD:+'***set***'}${NTFY_PASSWORD:-'(not set)'}${NC}"
echo ""
if [ -n "$NTFY_URL" ] && [ -n "$NTFY_TOPIC" ]; then
echo -e " Server: ${GREEN}$NTFY_URL${NC}" echo -e " Server: ${GREEN}$NTFY_URL${NC}"
echo -e " Topic: ${GREEN}$NTFY_TOPIC${NC}" echo -e " Topic: ${GREEN}$NTFY_TOPIC${NC}"
echo "" echo ""
@@ -37,7 +46,11 @@ send_ntfy() {
# Check for Basic Auth # Check for Basic Auth
if [ -n "$NTFY_USERNAME" ] && [ -n "$NTFY_PASSWORD" ]; then if [ -n "$NTFY_USERNAME" ] && [ -n "$NTFY_PASSWORD" ]; then
auth_args="-u $NTFY_USERNAME:$NTFY_PASSWORD" auth_args="-u $NTFY_USERNAME:$NTFY_PASSWORD"
echo -e " ${GREEN}${NC} Using Basic Authentication"
else
echo -e " ${YELLOW}${NC} No authentication (public topic)"
fi fi
echo ""
# Build rich message with metadata # Build rich message with metadata
local rich_message=$(cat <<EOF local rich_message=$(cat <<EOF
@@ -50,6 +63,8 @@ EOF
) )
echo -e " ${YELLOW}${NC} Sending push notification..." echo -e " ${YELLOW}${NC} Sending push notification..."
echo -e " ${YELLOW}${NC} Target: $NTFY_URL/$NTFY_TOPIC"
response=$(curl -s -w "\n%{http_code}" $auth_args -X POST "$NTFY_URL/$NTFY_TOPIC" \ response=$(curl -s -w "\n%{http_code}" $auth_args -X POST "$NTFY_URL/$NTFY_TOPIC" \
-H "Title: $ICON $TITLE" \ -H "Title: $ICON $TITLE" \
-H "Priority: $priority" \ -H "Priority: $priority" \
@@ -59,12 +74,21 @@ EOF
-d "$rich_message" 2>&1) -d "$rich_message" 2>&1)
http_code=$(echo "$response" | tail -n1) http_code=$(echo "$response" | tail -n1)
response_body=$(echo "$response" | head -n -1)
if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then if [ "$http_code" = "200" ] || [ "$http_code" = "201" ]; then
echo -e " ${GREEN}${NC} Notification sent successfully" echo -e " ${GREEN}${NC} Notification sent successfully (HTTP $http_code)"
else else
echo -e " ${RED}${NC} Failed to send notification (HTTP $http_code)" echo -e " ${RED}${NC} Failed to send notification (HTTP $http_code)"
if [ -n "$response_body" ]; then
echo -e " ${RED}Response:${NC} $response_body"
fi fi
fi
echo ""
else
echo -e " ${RED}${NC} Skipping Ntfy - Missing required configuration"
[ -z "$NTFY_URL" ] && echo -e " ${RED}${NC} NTFY_URL is not set"
[ -z "$NTFY_TOPIC" ] && echo -e " ${RED}${NC} NTFY_TOPIC is not set"
echo "" echo ""
fi fi
} }