Skip to content

Commit

Permalink
fix: escape chars for tg md
Browse files Browse the repository at this point in the history
  • Loading branch information
p0n1 committed Jan 20, 2025
1 parent e3c94b9 commit 22cfe75
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 5 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/escape_markdown.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# This script escapes special Markdown characters for Telegram API
# Usage:
# cat input.txt | ./escape_markdown.sh > output.txt
# OR
# echo "Your text here" | ./escape_markdown.sh

perl -pe 's/([_*[\]()~`>#+\-=\|{}.!])/\\$1/g'
41 changes: 36 additions & 5 deletions .github/workflows/notify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,18 @@ jobs:
name: Notify Telegram
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Make escape script executable
run: chmod +x .github/workflows/escape_markdown.sh

- name: Escape commit message
if: github.event_name == 'push'
id: escape_commit
run: |
echo "message=$(echo '${{ github.event.head_commit.message }}' | .github/workflows/escape_markdown.sh)" >> $GITHUB_OUTPUT
- name: Send Telegram Message on Push
if: github.event_name == 'push'
uses: appleboy/telegram-action@master
Expand All @@ -30,11 +42,17 @@ jobs:
📝 *Commit Message:*
```
${{ github.event.head_commit.message }}
${{ steps.escape_commit.outputs.message }}
```
🔗 [View Commit](https://github.com/${{ github.repository }}/commit/${{github.sha}})
- name: Escape PR title
if: github.event_name == 'pull_request'
id: escape_pr
run: |
echo "title=$(echo '${{ github.event.pull_request.title }}' | .github/workflows/escape_markdown.sh)" >> $GITHUB_OUTPUT
- name: Send Telegram Message on Pull Request
if: github.event_name == 'pull_request'
uses: appleboy/telegram-action@master
Expand All @@ -45,13 +63,19 @@ jobs:
message: |
🚀 *Pull Request ${{ github.event.action }} in ${{ github.repository }}*
📌 *Title:* ${{ github.event.pull_request.title }}
📌 *Title:* ${{ steps.escape_pr.outputs.title }}
🔢 *PR #:* ${{ github.event.pull_request.number }}
🚦 *State:* ${{ github.event.pull_request.state }}
👤 *Author:* ${{ github.event.pull_request.user.login }}
🔗 [View PR](${{ github.event.pull_request.html_url }})
- name: Escape issue title
if: github.event_name == 'issues'
id: escape_issue
run: |
echo "title=$(echo '${{ github.event.issue.title }}' | .github/workflows/escape_markdown.sh)" >> $GITHUB_OUTPUT
- name: Send Telegram Message on Issue
if: github.event_name == 'issues'
uses: appleboy/telegram-action@master
Expand All @@ -62,13 +86,20 @@ jobs:
message: |
🎫 *Issue ${{ github.event.action }} in ${{ github.repository }}*
📌 *Title:* ${{ github.event.issue.title }}
📌 *Title:* ${{ steps.escape_issue.outputs.title }}
🔢 *Issue #:* ${{ github.event.issue.number }}
🚦 *State:* ${{ github.event.issue.state }}
👤 *Author:* ${{ github.event.issue.user.login }}
🔗 [View Issue](${{ github.event.issue.html_url }})
- name: Escape release info
if: github.event_name == 'release'
id: escape_release
run: |
echo "name=$(echo '${{ github.event.release.name }}' | .github/workflows/escape_markdown.sh)" >> $GITHUB_OUTPUT
echo "body=$(echo '${{ github.event.release.body }}' | .github/workflows/escape_markdown.sh)" >> $GITHUB_OUTPUT
- name: Send Telegram Message on Release
if: github.event_name == 'release'
uses: appleboy/telegram-action@master
Expand All @@ -80,12 +111,12 @@ jobs:
🚀 *New Release Published in ${{ github.repository }}*
🏷️ *Tag:* ${{ github.event.release.tag_name }}
📛 *Name:* ${{ github.event.release.name }}
📛 *Name:* ${{ steps.escape_release.outputs.name }}
👤 *Author:* ${{ github.event.release.author.login }}
📝 *Description:*
```
${{ github.event.release.body }}
${{ steps.escape_release.outputs.body }}
```
🔗 [View Release](${{ github.event.release.html_url }})
Expand Down

0 comments on commit 22cfe75

Please sign in to comment.