mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-04-30 11:26:23 +00:00
Update notification service
This commit is contained in:
@@ -24,6 +24,7 @@ interface ChannelConfig {
|
|||||||
rich_format?: boolean
|
rich_format?: boolean
|
||||||
bot_token?: string
|
bot_token?: string
|
||||||
chat_id?: string
|
chat_id?: string
|
||||||
|
topic_id?: string // Telegram topic ID for supergroups with topics
|
||||||
url?: string
|
url?: string
|
||||||
token?: string
|
token?: string
|
||||||
webhook_url?: string
|
webhook_url?: string
|
||||||
@@ -1126,6 +1127,16 @@ export function NotificationSettings() {
|
|||||||
onChange={e => updateChannel("telegram", "chat_id", e.target.value)}
|
onChange={e => updateChannel("telegram", "chat_id", e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="space-y-1.5">
|
||||||
|
<Label className="text-[11px] text-muted-foreground">Topic ID <span className="text-muted-foreground/60">(optional)</span></Label>
|
||||||
|
<Input
|
||||||
|
className="h-7 text-xs font-mono"
|
||||||
|
placeholder="123456"
|
||||||
|
value={config.channels.telegram?.topic_id || ""}
|
||||||
|
onChange={e => updateChannel("telegram", "topic_id", e.target.value)}
|
||||||
|
/>
|
||||||
|
<p className="text-[10px] text-muted-foreground">For supergroups with topics enabled. Leave empty for regular chats.</p>
|
||||||
|
</div>
|
||||||
{/* Message format */}
|
{/* Message format */}
|
||||||
<div className="flex items-center justify-between py-1">
|
<div className="flex items-center justify-between py-1">
|
||||||
<div>
|
<div>
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ class TelegramChannel(NotificationChannel):
|
|||||||
'UNKNOWN': '\u26AA', # white circle
|
'UNKNOWN': '\u26AA', # white circle
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, bot_token: str, chat_id: str):
|
def __init__(self, bot_token: str, chat_id: str, topic_id: str = ''):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
token = bot_token.strip()
|
token = bot_token.strip()
|
||||||
# Strip 'bot' prefix if user included it (API_BASE already adds it)
|
# Strip 'bot' prefix if user included it (API_BASE already adds it)
|
||||||
@@ -143,6 +143,8 @@ class TelegramChannel(NotificationChannel):
|
|||||||
token = token[3:]
|
token = token[3:]
|
||||||
self.bot_token = token
|
self.bot_token = token
|
||||||
self.chat_id = chat_id.strip()
|
self.chat_id = chat_id.strip()
|
||||||
|
# Topic ID for supergroups with topics enabled (message_thread_id)
|
||||||
|
self.topic_id = topic_id.strip() if topic_id else ''
|
||||||
|
|
||||||
def validate_config(self) -> Tuple[bool, str]:
|
def validate_config(self) -> Tuple[bool, str]:
|
||||||
if not self.bot_token:
|
if not self.bot_token:
|
||||||
@@ -177,6 +179,12 @@ class TelegramChannel(NotificationChannel):
|
|||||||
'chat_id': self.chat_id,
|
'chat_id': self.chat_id,
|
||||||
'photo': photo_url,
|
'photo': photo_url,
|
||||||
}
|
}
|
||||||
|
# Add topic ID for supergroups with topics enabled
|
||||||
|
if self.topic_id:
|
||||||
|
try:
|
||||||
|
payload['message_thread_id'] = int(self.topic_id)
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
if caption:
|
if caption:
|
||||||
payload['caption'] = caption[:1024] # Telegram caption limit
|
payload['caption'] = caption[:1024] # Telegram caption limit
|
||||||
payload['parse_mode'] = 'HTML'
|
payload['parse_mode'] = 'HTML'
|
||||||
@@ -204,13 +212,20 @@ class TelegramChannel(NotificationChannel):
|
|||||||
|
|
||||||
def _post_message(self, text: str) -> Tuple[int, str]:
|
def _post_message(self, text: str) -> Tuple[int, str]:
|
||||||
url = self.API_BASE.format(token=self.bot_token)
|
url = self.API_BASE.format(token=self.bot_token)
|
||||||
payload = json.dumps({
|
payload_dict = {
|
||||||
'chat_id': self.chat_id,
|
'chat_id': self.chat_id,
|
||||||
'text': text,
|
'text': text,
|
||||||
'parse_mode': 'HTML',
|
'parse_mode': 'HTML',
|
||||||
'disable_web_page_preview': True,
|
'disable_web_page_preview': True,
|
||||||
}).encode('utf-8')
|
}
|
||||||
|
# Add topic ID for supergroups with topics enabled
|
||||||
|
if self.topic_id:
|
||||||
|
try:
|
||||||
|
payload_dict['message_thread_id'] = int(self.topic_id)
|
||||||
|
except ValueError:
|
||||||
|
pass # Invalid topic_id, skip
|
||||||
|
|
||||||
|
payload = json.dumps(payload_dict).encode('utf-8')
|
||||||
return self._http_request(url, payload, {'Content-Type': 'application/json'})
|
return self._http_request(url, payload, {'Content-Type': 'application/json'})
|
||||||
|
|
||||||
def _split_message(self, text: str) -> list:
|
def _split_message(self, text: str) -> list:
|
||||||
@@ -892,11 +907,12 @@ def create_channel(channel_type: str, config: Dict[str, str]) -> Optional[Notifi
|
|||||||
Channel instance or None if creation fails
|
Channel instance or None if creation fails
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
if channel_type == 'telegram':
|
if channel_type == 'telegram':
|
||||||
return TelegramChannel(
|
return TelegramChannel(
|
||||||
bot_token=config.get('bot_token', ''),
|
bot_token=config.get('bot_token', ''),
|
||||||
chat_id=config.get('chat_id', '')
|
chat_id=config.get('chat_id', ''),
|
||||||
)
|
topic_id=config.get('topic_id', '')
|
||||||
|
)
|
||||||
elif channel_type == 'gotify':
|
elif channel_type == 'gotify':
|
||||||
return GotifyChannel(
|
return GotifyChannel(
|
||||||
server_url=config.get('url', ''),
|
server_url=config.get('url', ''),
|
||||||
|
|||||||
Reference in New Issue
Block a user