feat: 新增 telegram 通知

This commit is contained in:
wfunc
2025-09-16 11:44:39 +08:00
parent 932b0e3f9d
commit f2dc834bba
4 changed files with 491 additions and 14 deletions

View File

@@ -62,6 +62,7 @@ class WebhookConfigService {
'feishu',
'slack',
'discord',
'telegram',
'custom',
'bark',
'smtp'
@@ -73,7 +74,7 @@ class WebhookConfigService {
}
// Bark和SMTP平台不使用标准URL
if (platform.type !== 'bark' && platform.type !== 'smtp') {
if (!['bark', 'smtp', 'telegram'].includes(platform.type)) {
if (!platform.url || !this.isValidUrl(platform.url)) {
throw new Error(`无效的webhook URL: ${platform.url}`)
}
@@ -117,6 +118,43 @@ class WebhookConfigService {
logger.warn('⚠️ Discord webhook URL格式可能不正确')
}
break
case 'telegram':
if (!platform.botToken) {
throw new Error('Telegram 平台必须提供机器人 Token')
}
if (!platform.chatId) {
throw new Error('Telegram 平台必须提供 Chat ID')
}
if (!platform.botToken.includes(':')) {
logger.warn('⚠️ Telegram 机器人 Token 格式可能不正确')
}
if (!/^[-\d]+$/.test(String(platform.chatId))) {
logger.warn('⚠️ Telegram Chat ID 应该是数字如为频道请确认已获取正确ID')
}
if (platform.apiBaseUrl) {
if (!this.isValidUrl(platform.apiBaseUrl)) {
throw new Error('Telegram API 基础地址格式无效')
}
const { protocol } = new URL(platform.apiBaseUrl)
if (!['http:', 'https:'].includes(protocol)) {
throw new Error('Telegram API 基础地址仅支持 http 或 https 协议')
}
}
if (platform.proxyUrl) {
if (!this.isValidUrl(platform.proxyUrl)) {
throw new Error('Telegram 代理地址格式无效')
}
const proxyProtocol = new URL(platform.proxyUrl).protocol
const supportedProtocols = ['http:', 'https:', 'socks4:', 'socks4a:', 'socks5:']
if (!supportedProtocols.includes(proxyProtocol)) {
throw new Error('Telegram 代理仅支持 http/https/socks 协议')
}
}
break
case 'custom':
// 自定义webhook用户自行负责格式
break