agent-zero/api/notification_create.py
Alessandro d1827e6c66
Some checks are pending
Build And Publish Docker Images / plan (push) Waiting to run
Build And Publish Docker Images / build (push) Blocked by required conditions
Refactor: use user locale for time displays
Add user-configurable timezone and 12/24-hour preferences, then wire them through settings, runtime snapshots, scheduler payloads, wait handling, notifications, backups, memory, plugin metadata, and frontend formatters.

Keep UTC as the boundary for absolute instants while serializing user-facing dates in the configured or browser-resolved timezone. Preserve scheduler wall-clock inputs in the selected timezone, propagate TZ into desktop/runtime process environments, and restart active desktop sessions when the runtime timezone changes.

Cover the risky paths with timezone regression tests for settings normalization, auto and fixed timezone resolution, scheduler round-trips, memory timestamp conversion, and desktop timezone sync.
2026-05-21 15:26:00 +02:00

68 lines
2.4 KiB
Python

from helpers.api import ApiHandler
from flask import Request, Response
from helpers.notification import NotificationManager, NotificationPriority, NotificationType
class NotificationCreate(ApiHandler):
@classmethod
def requires_auth(cls) -> bool:
return True
async def process(self, input: dict, request: Request) -> dict | Response:
# Extract notification data
notification_type = input.get("type", NotificationType.INFO.value)
priority = input.get("priority", NotificationPriority.NORMAL.value)
message = input.get("message", "")
title = input.get("title", "")
detail = input.get("detail", "")
display_time = input.get("display_time", 3) # Default to 3 seconds
group = input.get("group", "") # Group parameter for notification grouping
notification_id = input.get("id", "")
# Validate required fields
if not message:
return {"success": False, "error": "Message is required"}
# Validate display_time
try:
display_time = int(display_time)
if display_time < 0:
display_time = 3 # Reset to default if negative
except (ValueError, TypeError):
display_time = 3 # Reset to default if not numeric
# Validate notification type
try:
if isinstance(notification_type, str):
notification_type = NotificationType(notification_type.lower())
except ValueError:
return {
"success": False,
"error": f"Invalid notification type: {notification_type}",
}
# Create notification using the appropriate helper method
try:
notification = NotificationManager.send_notification(
notification_type,
priority,
message,
title,
detail,
display_time,
group,
notification_id,
)
return {
"success": True,
"notification_id": notification.id,
"notification": notification.output(),
"message": "Notification created successfully",
}
except Exception as e:
return {
"success": False,
"error": f"Failed to create notification: {str(e)}",
}