|
| 1 | +name: Telegram Notifications |
| 2 | + |
| 3 | +on: |
| 4 | + release: |
| 5 | + types: [published] |
| 6 | + issues: |
| 7 | + types: [opened] |
| 8 | + issue_comment: |
| 9 | + types: [created] |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: read |
| 13 | + |
| 14 | +jobs: |
| 15 | + notify: |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - uses: actions/github-script@v7 |
| 19 | + env: |
| 20 | + TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} |
| 21 | + TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }} |
| 22 | + with: |
| 23 | + script: | |
| 24 | + const token = process.env.TELEGRAM_BOT_TOKEN; |
| 25 | + const chatId = process.env.TELEGRAM_CHAT_ID; |
| 26 | + if (!token || !chatId) return; |
| 27 | +
|
| 28 | + let text = ''; |
| 29 | + const event = context.eventName; |
| 30 | + const repo = context.payload.repository.full_name; |
| 31 | +
|
| 32 | + if (event === 'release') { |
| 33 | + const r = context.payload.release; |
| 34 | + const body = r.body ? r.body.substring(0, 500) : ''; |
| 35 | + text = `🚀 <b>New Release: ${r.tag_name}</b>\n\n${body}\n\n<a href="${r.html_url}">Release notes</a> | <a href="https://github.com/${repo}">GitHub</a>`; |
| 36 | + } else if (event === 'issues' && context.payload.action === 'opened') { |
| 37 | + // Skip bot-created issues |
| 38 | + if (context.payload.issue.user.type === 'Bot') return; |
| 39 | + const i = context.payload.issue; |
| 40 | + text = `📋 <b>New Issue #${i.number}</b>: ${i.title}\n\nby ${i.user.login}\n<a href="${i.html_url}">View issue</a>`; |
| 41 | + } else if (event === 'issue_comment' && context.payload.action === 'created') { |
| 42 | + // Only post maintainer comments |
| 43 | + const c = context.payload.comment; |
| 44 | + if (c.user.login !== 'dvershinin') return; |
| 45 | + // Skip auto-reply bot comments |
| 46 | + if (c.user.type === 'Bot') return; |
| 47 | + const i = context.payload.issue; |
| 48 | + const snippet = c.body.substring(0, 300); |
| 49 | + text = `💬 <b>Comment on #${i.number}</b>: ${i.title}\n\n${snippet}\n\n<a href="${c.html_url}">View comment</a>`; |
| 50 | + } |
| 51 | +
|
| 52 | + if (!text) return; |
| 53 | +
|
| 54 | + await fetch(`https://api.telegram.org/bot${token}/sendMessage`, { |
| 55 | + method: 'POST', |
| 56 | + headers: { 'Content-Type': 'application/json' }, |
| 57 | + body: JSON.stringify({ |
| 58 | + chat_id: chatId, |
| 59 | + text: text, |
| 60 | + parse_mode: 'HTML', |
| 61 | + disable_web_page_preview: true |
| 62 | + }) |
| 63 | + }); |
0 commit comments