Restructure data model: TrackingConfig + TemplateConfig entities
Some checks failed
Validate / Hassfest (push) Has been cancelled
Some checks failed
Validate / Hassfest (push) Has been cancelled
Major model restructuring for clean separation of concerns: New entities: - TrackingConfig: What to react to (event types, asset filters, periodic/scheduled/memory mode config) - reusable across targets - TemplateConfig: All ~15 template slots from blueprint (event messages, asset formatting, date/location, scheduled messages) with full defaults - separate entities per locale Changed entities: - AlbumTracker: Simplified to album selection + polling + target_ids (removed event_types, template_id, all filter fields) - NotificationTarget: Extended with tracking_config_id and template_config_id FKs (many-to-one, reusable configs) Removed entities: - MessageTemplate (replaced by TemplateConfig) - ScheduledJob (absorbed into TrackingConfig) Updated services: - watcher.py: Each target checked against its own tracking_config for event filtering before sending notification - notifier.py: Uses target's template_config to select the right template slot based on event type New API routes: - /api/tracking-configs/* (CRUD) - /api/template-configs/* (CRUD + per-slot preview) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -11,7 +11,7 @@ from jinja2.sandbox import SandboxedEnvironment
|
||||
|
||||
from immich_watcher_core.telegram.client import TelegramClient
|
||||
|
||||
from ..database.models import MessageTemplate, NotificationTarget
|
||||
from ..database.models import NotificationTarget, TemplateConfig
|
||||
from ..webhook.client import WebhookClient
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
@@ -33,7 +33,7 @@ def render_template(template_body: str, context: dict[str, Any]) -> str:
|
||||
async def send_notification(
|
||||
target: NotificationTarget,
|
||||
event_data: dict[str, Any],
|
||||
template: MessageTemplate | None = None,
|
||||
template_config: TemplateConfig | None = None,
|
||||
use_ai_caption: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
"""Send a notification to a target using event data.
|
||||
@@ -41,7 +41,7 @@ async def send_notification(
|
||||
Args:
|
||||
target: Notification destination (telegram or webhook)
|
||||
event_data: Album change event data (album_name, added_count, etc.)
|
||||
template: Optional message template (uses default if None)
|
||||
template_config: Optional template config with per-event templates
|
||||
use_ai_caption: If True, generate caption with Claude AI instead of template
|
||||
"""
|
||||
message = None
|
||||
@@ -54,7 +54,18 @@ async def send_notification(
|
||||
|
||||
# Fall back to template rendering
|
||||
if message is None:
|
||||
template_body = template.body if template else DEFAULT_TEMPLATE
|
||||
template_body = DEFAULT_TEMPLATE
|
||||
if template_config:
|
||||
# Select the right template slot based on event type
|
||||
change_type = event_data.get("change_type", "")
|
||||
slot_map = {
|
||||
"assets_added": "message_assets_added",
|
||||
"assets_removed": "message_assets_removed",
|
||||
"album_renamed": "message_album_renamed",
|
||||
"album_deleted": "message_album_deleted",
|
||||
}
|
||||
slot = slot_map.get(change_type, "message_assets_added")
|
||||
template_body = getattr(template_config, slot, DEFAULT_TEMPLATE) or DEFAULT_TEMPLATE
|
||||
try:
|
||||
message = render_template(template_body, event_data)
|
||||
except jinja2.TemplateError as e:
|
||||
|
||||
Reference in New Issue
Block a user