feat: test menu dropdown, split text/media messages, target settings, provider URL links

- Replace 3 test buttons with unified dropdown menu (basic/periodic/scheduled/memory)
- Send text message first, then assets as reply (not combined caption+media)
- Pass all target config settings to Telegram client (disable_url_preview, max_media, chunk_delay, etc.)
- Real data test notifications for periodic/scheduled/memory (fetch from Immich)
- Provider card URL is now a clickable hyperlink
- Localized test type labels (EN/RU)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-20 16:34:25 +03:00
parent 03c5c66eed
commit 5015e378fe
9 changed files with 407 additions and 78 deletions
@@ -1,5 +1,7 @@
"""Status/dashboard API route."""
from datetime import datetime, timedelta, timezone
from fastapi import APIRouter, Depends, Query
from sqlmodel import func, select
from sqlmodel.ext.asyncio.session import AsyncSession
@@ -89,3 +91,46 @@ async def get_status(
for e in recent_events.all()
],
}
@router.get("/chart")
async def get_event_chart(
user: User = Depends(get_current_user),
session: AsyncSession = Depends(get_session),
days: int = Query(14, ge=1, le=90),
):
"""Return daily event counts by type for the last N days."""
cutoff = datetime.now(timezone.utc) - timedelta(days=days)
day_col = func.date(EventLog.created_at)
query = (
select(
day_col.label("day"),
EventLog.event_type,
func.count().label("count"),
)
.join(Tracker, EventLog.tracker_id == Tracker.id)
.where(Tracker.user_id == user.id, EventLog.created_at >= cutoff)
.group_by(day_col, EventLog.event_type)
.order_by(day_col)
)
rows = (await session.exec(query)).all()
# Build a dict: { "2026-03-15": { "assets_added": 3, ... }, ... }
by_day: dict[str, dict[str, int]] = {}
for row in rows:
day_str = str(row.day)
if day_str not in by_day:
by_day[day_str] = {}
by_day[day_str][row.event_type] = row.count
# Fill in missing days so the frontend gets a continuous series
result = []
for i in range(days):
d = (datetime.now(timezone.utc) - timedelta(days=days - 1 - i)).strftime("%Y-%m-%d")
counts = by_day.get(d, {})
result.append({"date": d, **counts})
return {"days": result}
@@ -11,6 +11,7 @@ from ..auth.dependencies import get_current_user
from ..database.engine import get_session
from ..database.models import (
NotificationTarget,
ServiceProvider,
TemplateConfig,
Tracker,
TrackerTarget,
@@ -148,16 +149,24 @@ async def delete_tracker_target(
await session.commit()
@router.post("/{tracker_target_id}/test")
@router.post("/{tracker_target_id}/test/{test_type}")
async def test_tracker_target(
tracker_id: int,
tracker_target_id: int,
test_type: str,
locale: str = Query("en"),
user: User = Depends(get_current_user),
session: AsyncSession = Depends(get_session),
):
"""Send a test notification to a specific linked target."""
await _get_user_tracker(session, tracker_id, user.id)
"""Send a test notification using real provider data.
test_type: basic | periodic | scheduled | memory
"""
valid_types = {"basic", "periodic", "scheduled", "memory"}
if test_type not in valid_types:
raise HTTPException(status_code=400, detail=f"Invalid test type. Must be one of: {', '.join(valid_types)}")
tracker = await _get_user_tracker(session, tracker_id, user.id)
tt = await session.get(TrackerTarget, tracker_target_id)
if not tt or tt.tracker_id != tracker_id:
raise HTTPException(status_code=404, detail="Tracker-target link not found")
@@ -166,62 +175,42 @@ async def test_tracker_target(
if not target:
raise HTTPException(status_code=404, detail="Target not found")
from ..services.notifier import send_test_notification
r = await send_test_notification(target, locale=locale)
return {"target": target.name, **r}
@router.post("/{tracker_target_id}/test-periodic")
async def test_periodic_tracker_target(
tracker_id: int,
tracker_target_id: int,
user: User = Depends(get_current_user),
session: AsyncSession = Depends(get_session),
):
"""Send a test periodic summary to a specific linked target."""
await _get_user_tracker(session, tracker_id, user.id)
tt = await session.get(TrackerTarget, tracker_target_id)
if not tt or tt.tracker_id != tracker_id:
raise HTTPException(status_code=404, detail="Tracker-target link not found")
target = await session.get(NotificationTarget, tt.target_id)
if not target:
raise HTTPException(status_code=404, detail="Target not found")
if test_type == "basic":
from ..services.notifier import send_test_notification
r = await send_test_notification(target, locale=locale)
return {"target": target.name, **r}
# For periodic/scheduled/memory — fetch real data from provider
template_config = None
if tt.template_config_id:
template_config = await session.get(TemplateConfig, tt.template_config_id)
template_str = (template_config.periodic_summary_message if template_config else "") or ""
from ..services.notifier import send_test_template_notification
r = await send_test_template_notification(target, "periodic_summary", template_str)
return {"target": target.name, **r}
slot_map = {
"periodic": "periodic_summary_message",
"scheduled": "scheduled_assets_message",
"memory": "memory_mode_message",
}
template_str = getattr(template_config, slot_map[test_type], "") if template_config else ""
# Load provider and tracker data eagerly before aiohttp context
provider = await session.get(ServiceProvider, tracker.provider_id)
if not provider:
raise HTTPException(status_code=404, detail="Provider not found")
provider_config = dict(provider.config)
collection_ids = list(tracker.collection_ids or [])
@router.post("/{tracker_target_id}/test-memory")
async def test_memory_tracker_target(
tracker_id: int,
tracker_target_id: int,
user: User = Depends(get_current_user),
session: AsyncSession = Depends(get_session),
):
"""Send a test memory/on-this-day notification to a specific linked target."""
await _get_user_tracker(session, tracker_id, user.id)
tt = await session.get(TrackerTarget, tracker_target_id)
if not tt or tt.tracker_id != tracker_id:
raise HTTPException(status_code=404, detail="Tracker-target link not found")
target = await session.get(NotificationTarget, tt.target_id)
if not target:
raise HTTPException(status_code=404, detail="Target not found")
template_config = None
if tt.template_config_id:
template_config = await session.get(TemplateConfig, tt.template_config_id)
template_str = (template_config.memory_mode_message if template_config else "") or ""
from ..services.notifier import send_test_template_notification
r = await send_test_template_notification(target, "memory_mode", template_str)
# Fetch real data from provider
from ..services.notifier import send_real_data_notification
r = await send_real_data_notification(
target=target,
template_str=template_str,
test_type=test_type,
provider_type=provider.type,
provider_config=provider_config,
collection_ids=collection_ids,
date_format=template_config.date_format if template_config else "%d.%m.%Y, %H:%M UTC",
date_only_format=template_config.date_only_format if template_config and hasattr(template_config, "date_only_format") else "%d.%m.%Y",
)
return {"target": target.name, **r}