Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions .github/workflows/send-telegram-message.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ 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)'
secrets:
TELEGRAM_API_URL:
required: true
TELEGRAM_CHAT_ID:
required: true

jobs:
send-message:
Expand All @@ -21,8 +30,25 @@ 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}}')
curl -X POST "${{ secrets.TELEGRAM_API_URL }}" \
payload=$(jq -n --arg text "$MESSAGE_TEXT" --arg chat_id "$CHAT_ID" '{chat_id: $chat_id, message: {text: $text}}')

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
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 🚀

Expand All @@ -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 🎉
Expand Down