add telegram notification

This commit is contained in:
pompurin404 2024-09-08 14:56:13 +08:00
parent 1962414ed6
commit 2843bf94b2
No known key found for this signature in database
4 changed files with 54 additions and 2 deletions

View File

@ -202,6 +202,10 @@ jobs:
version: 9 version: 9
- name: Build Latest - name: Build Latest
run: pnpm install && pnpm updater run: pnpm install && pnpm updater
- name: Telegram Notification
env:
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
run: pnpm temegram
- name: Publish Release - name: Publish Release
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:

View File

@ -9,8 +9,8 @@
<a href="https://github.com/pompurin404/mihomo-party/releases"> <a href="https://github.com/pompurin404/mihomo-party/releases">
<img src="https://img.shields.io/github/release/pompurin404/mihomo-party/all.svg"> <img src="https://img.shields.io/github/release/pompurin404/mihomo-party/all.svg">
</a> </a>
<a href="https://t.me/mihomo_party"> <a href="https://t.me/mihomo_party_channel">
<img src="https://img.shields.io/badge/Telegram-group-blue?logo=telegram"> <img src="https://img.shields.io/badge/Telegram-Channel-blue?logo=telegram">
</a> </a>
</p> </p>
<div align='center'> <div align='center'>

View File

@ -14,6 +14,7 @@
"prepare": "node scripts/prepare.mjs", "prepare": "node scripts/prepare.mjs",
"updater": "node scripts/updater.mjs", "updater": "node scripts/updater.mjs",
"checksum": "node scripts/checksum.mjs", "checksum": "node scripts/checksum.mjs",
"telegram": "node scripts/telegram.mjs",
"dev": "electron-vite dev", "dev": "electron-vite dev",
"postinstall": "electron-builder install-app-deps", "postinstall": "electron-builder install-app-deps",
"build:win": "electron-vite build && electron-builder --publish never --win", "build:win": "electron-vite build && electron-builder --publish never --win",

47
scripts/telegram.mjs Normal file
View File

@ -0,0 +1,47 @@
import axios from 'axios'
import { readFileSync } from 'fs'
const pkg = readFileSync('package.json', 'utf-8')
const changelog = readFileSync('changelog.md', 'utf-8')
const { version } = JSON.parse(pkg)
let content = `<b>🌟Mihomo Party v${version} 正式发布</b>\n\n`
for (const line of changelog.split('\n')) {
if (line.length === 0) {
content += '\n'
} else if (line.startsWith('### ')) {
content += `<b>${line.replace('### ', '')}</b>\n`
} else {
content += `${line}\n`
}
}
axios.post(`https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`, {
chat_id: '@mihomo_party_channel',
text: content,
parse_mode: 'HTML',
reply_markup: {
inline_keyboard: [
[
{
text: '官方群组',
url: 'https://t.me/mihomo_party'
},
{
text: '官方频道',
url: 'https://t.me/mihomo_party_channel'
}
],
[
{
text: '官方文档',
url: 'https://mihomo.party'
}
],
[
{
text: '前往下载',
url: `https://github.com/pompurin404/mihomo-party/releases/tag/v${version}`
}
]
]
}
})