mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-24 09:41:17 +00:00
feat: 新增 telegram 通知
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user