-
Notifications
You must be signed in to change notification settings - Fork 115
Expand file tree
/
Copy pathtelegram_notify.sh
More file actions
executable file
·83 lines (66 loc) · 2.36 KB
/
telegram_notify.sh
File metadata and controls
executable file
·83 lines (66 loc) · 2.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# Telegram notification script for DAppNode releases
# This script sends a notification to a Telegram chat when a new release is created
set -e
# Function to display usage
show_usage() {
echo "Usage: $0 <release_version> <release_url>"
echo "Example: $0 v0.2.51 https://github.com/dappnode/DAppNode/releases/tag/v0.2.51"
exit 1
}
# Function to send telegram message
send_telegram_message() {
local message="$1"
local bot_token="$TELEGRAM_BOT_TOKEN"
local chat_id="$TELEGRAM_CHAT_ID"
if [ -z "$bot_token" ]; then
echo "Error: TELEGRAM_BOT_TOKEN environment variable is not set"
exit 1
fi
if [ -z "$chat_id" ]; then
echo "Error: TELEGRAM_CHAT_ID environment variable is not set"
exit 1
fi
# Send the message using curl
curl -s -X POST "https://api.telegram.org/bot${bot_token}/sendMessage" \
-H "Content-Type: application/json" \
-d "{
\"chat_id\": \"${chat_id}\",
\"text\": \"${message}\",
\"parse_mode\": \"Markdown\",
\"disable_web_page_preview\": false
}" > /dev/null
local exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Telegram notification sent successfully"
else
echo "Failed to send Telegram notification (exit code: $exit_code)"
exit 1
fi
}
# Check if required arguments are provided
if [ $# -ne 2 ]; then
echo "Error: Missing required arguments"
show_usage
fi
RELEASE_VERSION="$1"
RELEASE_URL="$2"
# Validate release version format
if [[ ! $RELEASE_VERSION =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Error: Release version must be in format vX.Y.Z (e.g., v0.2.51)"
exit 1
fi
# Validate release URL
if [[ ! $RELEASE_URL =~ ^https://github\.com/dappnode/DAppNode/releases/tag/.+ ]]; then
echo "Error: Invalid release URL format"
exit 1
fi
# Create the message
MESSAGE="🚀 *New DAppNode Release Available!*
📦 **Version:** \`${RELEASE_VERSION}\`
🔗 **Download:** [${RELEASE_VERSION}](${RELEASE_URL})
The latest DAppNode release is now available with updated core packages and improvements. Visit the release page to download the installation ISOs and view the complete changelog.
#DAppNode #Release #Decentralized"
# Send the notification
echo "Sending Telegram notification for release ${RELEASE_VERSION}..."
send_telegram_message "$MESSAGE"