mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2026-05-01 03:46:22 +00:00
Update notification service
This commit is contained in:
@@ -1746,7 +1746,7 @@ export function NotificationSettings() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="ml-8 space-y-1 text-muted-foreground text-xs">
|
<div className="ml-8 space-y-1 text-muted-foreground text-xs">
|
||||||
<p>After creating the bot, BotFather will give you a token like:</p>
|
<p>After creating the bot, BotFather will give you a token like:</p>
|
||||||
<code className="block bg-muted px-2 py-1 rounded text-[11px] mt-1">{"<bot_id>:<bot_secret>"}</code>
|
<code className="block bg-muted px-2 py-1 rounded text-[11px] mt-1">xxxxxxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</code>
|
||||||
<p className="mt-1">Copy this token and paste it in the <strong>Bot Token</strong> field.</p>
|
<p className="mt-1">Copy this token and paste it in the <strong>Bot Token</strong> field.</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -89,12 +89,26 @@ export async function fetchApi<T>(endpoint: string, options?: RequestInit): Prom
|
|||||||
cache: "no-store",
|
cache: "no-store",
|
||||||
})
|
})
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
if (response.status === 401) {
|
if (response.status === 401) {
|
||||||
throw new Error(`Unauthorized: ${endpoint}`)
|
console.error("[v0] fetchApi: 401 UNAUTHORIZED -", endpoint, "- Token present:", !!token)
|
||||||
|
throw new Error(`Unauthorized: ${endpoint}`)
|
||||||
|
}
|
||||||
|
throw new Error(`API request failed: ${response.status} ${response.statusText}`)
|
||||||
}
|
}
|
||||||
throw new Error(`API request failed: ${response.status} ${response.statusText}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return response.json()
|
// Check content type to ensure we're getting JSON
|
||||||
|
const contentType = response.headers.get("content-type")
|
||||||
|
if (!contentType || !contentType.includes("application/json")) {
|
||||||
|
const text = await response.text()
|
||||||
|
console.error("[v0] fetchApi: Expected JSON but got:", contentType, "- Body preview:", text.substring(0, 200))
|
||||||
|
throw new Error(`Expected JSON response but got ${contentType || "unknown content type"}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await response.json()
|
||||||
|
} catch (jsonError) {
|
||||||
|
console.error("[v0] fetchApi: JSON parse error for", endpoint, "-", jsonError)
|
||||||
|
throw new Error(`Invalid JSON response from ${endpoint}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -756,8 +756,10 @@ class NotificationManager:
|
|||||||
# ── Per-channel AI enhancement ──
|
# ── Per-channel AI enhancement ──
|
||||||
# Apply AI with channel-specific detail level and emoji setting
|
# Apply AI with channel-specific detail level and emoji setting
|
||||||
# If AI is enabled AND rich_format is on, AI will include emojis directly
|
# If AI is enabled AND rich_format is on, AI will include emojis directly
|
||||||
|
# Pass channel_type so AI knows whether to append original (email only)
|
||||||
|
channel_ai_config = {**ai_config, 'channel_type': ch_name}
|
||||||
ai_result = format_with_ai_full(
|
ai_result = format_with_ai_full(
|
||||||
ch_title, ch_body, severity, ai_config,
|
ch_title, ch_body, severity, channel_ai_config,
|
||||||
detail_level=detail_level,
|
detail_level=detail_level,
|
||||||
journal_context=journal_context,
|
journal_context=journal_context,
|
||||||
use_emojis=use_rich_format
|
use_emojis=use_rich_format
|
||||||
@@ -1070,8 +1072,10 @@ class NotificationManager:
|
|||||||
rich_key = f'{ch_name}.rich_format'
|
rich_key = f'{ch_name}.rich_format'
|
||||||
use_rich_format = self._config.get(rich_key, 'false') == 'true'
|
use_rich_format = self._config.get(rich_key, 'false') == 'true'
|
||||||
|
|
||||||
|
# Pass channel_type so AI knows whether to append original (email only)
|
||||||
|
channel_ai_config = {**ai_config, 'channel_type': ch_name}
|
||||||
ai_result = format_with_ai_full(
|
ai_result = format_with_ai_full(
|
||||||
title, message, severity, ai_config,
|
title, message, severity, channel_ai_config,
|
||||||
detail_level=detail_level,
|
detail_level=detail_level,
|
||||||
use_emojis=use_rich_format
|
use_emojis=use_rich_format
|
||||||
)
|
)
|
||||||
@@ -1188,8 +1192,10 @@ class NotificationManager:
|
|||||||
)
|
)
|
||||||
|
|
||||||
# Apply AI enhancement (translates to configured language)
|
# Apply AI enhancement (translates to configured language)
|
||||||
|
# Pass channel_type so AI knows whether to append original (email only)
|
||||||
|
channel_ai_config = {**ai_config, 'channel_type': ch_name}
|
||||||
ai_result = format_with_ai_full(
|
ai_result = format_with_ai_full(
|
||||||
base_title, base_message, 'INFO', ai_config,
|
base_title, base_message, 'INFO', channel_ai_config,
|
||||||
detail_level=detail_level,
|
detail_level=detail_level,
|
||||||
use_emojis=use_rich_format
|
use_emojis=use_rich_format
|
||||||
)
|
)
|
||||||
@@ -1206,7 +1212,7 @@ class NotificationManager:
|
|||||||
# Translate caption if AI is active
|
# Translate caption if AI is active
|
||||||
if ai_enabled:
|
if ai_enabled:
|
||||||
caption_result = format_with_ai_full(
|
caption_result = format_with_ai_full(
|
||||||
'', logo_caption, 'INFO', ai_config,
|
'', logo_caption, 'INFO', channel_ai_config,
|
||||||
detail_level='brief', use_emojis=use_rich_format
|
detail_level='brief', use_emojis=use_rich_format
|
||||||
)
|
)
|
||||||
caption = caption_result.get('body', logo_caption)
|
caption = caption_result.get('body', logo_caption)
|
||||||
|
|||||||
@@ -1675,6 +1675,9 @@ class AIEnhancer:
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
result = self._provider.generate(system_prompt, user_msg, max_tokens)
|
result = self._provider.generate(system_prompt, user_msg, max_tokens)
|
||||||
|
if result is None:
|
||||||
|
print(f"[AIEnhancer] Provider returned None - possible timeout or connection issue")
|
||||||
|
return None
|
||||||
return self._parse_ai_response(result, title, body)
|
return self._parse_ai_response(result, title, body)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[AIEnhancer] Enhancement failed: {e}")
|
print(f"[AIEnhancer] Enhancement failed: {e}")
|
||||||
@@ -1811,9 +1814,13 @@ def format_with_ai_full(title: str, body: str, severity: str,
|
|||||||
result_title = enhanced.get('title', title)
|
result_title = enhanced.get('title', title)
|
||||||
result_body = enhanced.get('body', body)
|
result_body = enhanced.get('body', body)
|
||||||
|
|
||||||
# For detailed level (email), append original message for reference
|
# For email channel with detailed level, append original message for reference
|
||||||
# This ensures full technical data is available even after AI processing
|
# This ensures full technical data is available even after AI processing
|
||||||
if detail_level == 'detailed' and body and len(body) > 50:
|
# Only for email - other channels (Telegram, Discord, Gotify) should not get duplicates
|
||||||
|
channel_type = ai_config.get('channel_type', '').lower()
|
||||||
|
is_email = channel_type == 'email'
|
||||||
|
|
||||||
|
if is_email and detail_level == 'detailed' and body and len(body) > 50:
|
||||||
# Only append if original has substantial content
|
# Only append if original has substantial content
|
||||||
result_body += "\n\n" + "-" * 40 + "\n"
|
result_body += "\n\n" + "-" * 40 + "\n"
|
||||||
result_body += "Original message:\n"
|
result_body += "Original message:\n"
|
||||||
|
|||||||
Reference in New Issue
Block a user