Skip to content

Commit c677ad5

Browse files
committed
fix(ci): escape HTML in Telegram release notes and surface API errors
1 parent 0d6ccbf commit c677ad5

1 file changed

Lines changed: 13 additions & 8 deletions

File tree

scripts/ci/notify-telegram.sh

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ fi
1616
RELEASE_URL="https://github.com/TableProApp/TablePro/releases/tag/v${VERSION}"
1717
NOTES=$(cat release_notes.md 2>/dev/null || echo "Bug fixes and improvements")
1818

19-
# Convert CHANGELOG markdown to Telegram HTML:
20-
# ### Header → <b>Header</b>
21-
# - item → • item
22-
# `code` → <code>code</code>
23-
# blank lines → removed
24-
FORMATTED=$(echo "$NOTES" | sed -E \
19+
ESCAPED=$(echo "$NOTES" | sed -e 's/&/\&amp;/g' -e 's/</\&lt;/g' -e 's/>/\&gt;/g')
20+
21+
FORMATTED=$(echo "$ESCAPED" | sed -E \
2522
-e 's/^### (.+)$/<b>\1<\/b>/' \
2623
-e 's/^- /• /' \
2724
-e 's/`([^`]+)`/<code>\1<\/code>/g' \
@@ -36,6 +33,14 @@ PAYLOAD=$(jq -n \
3633
'{chat_id: $chat_id, text: $text, parse_mode: "HTML", disable_web_page_preview: true}
3734
+ (if $topic_id != "" then {message_thread_id: ($topic_id | tonumber)} else {} end)')
3835

39-
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
36+
RESPONSE=$(curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
4037
-H "Content-Type: application/json" \
41-
-d "$PAYLOAD"
38+
-d "$PAYLOAD")
39+
40+
if echo "$RESPONSE" | jq -e '.ok == true' > /dev/null; then
41+
echo "Telegram notification sent for v${VERSION}"
42+
else
43+
echo "Telegram API rejected the message:"
44+
echo "$RESPONSE" | jq .
45+
exit 1
46+
fi

0 commit comments

Comments
 (0)