From b6e7040e1f0e7293b682bcf3d5ae551bad193b22 Mon Sep 17 00:00:00 2001 From: Domen Gabrovsek Date: Mon, 12 Jan 2026 22:09:48 +0100 Subject: [PATCH 1/2] feat: add support for multiple chat ids --- .github/workflows/send-telegram-message.yml | 7 ++++++- README.md | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/send-telegram-message.yml b/.github/workflows/send-telegram-message.yml index bf75e28..25a2f05 100644 --- a/.github/workflows/send-telegram-message.yml +++ b/.github/workflows/send-telegram-message.yml @@ -12,6 +12,10 @@ on: required: true type: string description: 'Message text to send' + chat_id: + required: false + type: string + description: 'Telegram chat ID (defaults to TELEGRAM_CHAT_ID secret if not provided)' jobs: send-message: @@ -21,8 +25,9 @@ jobs: - name: Send Telegram notification env: MESSAGE_TEXT: ${{ inputs.message }} + CHAT_ID: ${{ inputs.chat_id || secrets.TELEGRAM_CHAT_ID }} run: | - payload=$(jq -n --arg text "$MESSAGE_TEXT" '{message: {text: $text}}') + payload=$(jq -n --arg text "$MESSAGE_TEXT" --arg chat_id "$CHAT_ID" '{chat_id: $chat_id, message: {text: $text}}') curl -X POST "${{ secrets.TELEGRAM_API_URL }}" \ -H "Content-Type: application/json" \ -d "$payload" diff --git a/README.md b/README.md index e1bb215..6df3b20 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,9 @@ GitHub Actions that I reuse in other repos to send messages regarding updates to ## Setup 🔧 -Add `TELEGRAM_API_URL` secret to this repository (Settings → Secrets → Actions). +Add these secrets to your repository (Settings → Secrets → Actions): +- `TELEGRAM_API_URL` - The webhook URL for your Telegram bot API +- `TELEGRAM_CHAT_ID` - Default Telegram chat ID where messages will be sent ## Workflows 🚀 @@ -18,6 +20,8 @@ jobs: uses: domengabrovsek/github-actions/.github/workflows/send-telegram-message.yml@master with: message: "Your message here" + # Optional: Override default chat_id from TELEGRAM_CHAT_ID secret + # chat_id: "987654321" ``` ### PR Opened Notification 🎉 From 731570b144ba6619aed971cf8f8bf558fffc4d5a Mon Sep 17 00:00:00 2001 From: Domen Gabrovsek Date: Mon, 12 Jan 2026 22:18:30 +0100 Subject: [PATCH 2/2] improve validation --- .github/workflows/send-telegram-message.yml | 25 +++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/.github/workflows/send-telegram-message.yml b/.github/workflows/send-telegram-message.yml index 25a2f05..6ec940c 100644 --- a/.github/workflows/send-telegram-message.yml +++ b/.github/workflows/send-telegram-message.yml @@ -16,6 +16,11 @@ on: required: false type: string description: 'Telegram chat ID (defaults to TELEGRAM_CHAT_ID secret if not provided)' + secrets: + TELEGRAM_API_URL: + required: true + TELEGRAM_CHAT_ID: + required: true jobs: send-message: @@ -28,6 +33,22 @@ jobs: CHAT_ID: ${{ inputs.chat_id || secrets.TELEGRAM_CHAT_ID }} run: | payload=$(jq -n --arg text "$MESSAGE_TEXT" --arg chat_id "$CHAT_ID" '{chat_id: $chat_id, message: {text: $text}}') - curl -X POST "${{ secrets.TELEGRAM_API_URL }}" \ + + echo "Sending notification to Telegram..." + response=$(curl -s -w "\n%{http_code}" -X POST "${{ secrets.TELEGRAM_API_URL }}" \ -H "Content-Type: application/json" \ - -d "$payload" + -d "$payload") + + http_code=$(echo "$response" | tail -n1) + body=$(echo "$response" | sed '$d') + + echo "Response status: $http_code" + echo "Response body: $body" + + if [ "$http_code" -ge 200 ] && [ "$http_code" -lt 300 ]; then + echo "✅ Notification sent successfully!" + exit 0 + else + echo "❌ Failed to send notification (HTTP $http_code)" + exit 1 + fi