feat: rich command templates with public links + media text-first flow

- Command templates now match notification template style: type icons,
  linked filenames via album shared links, location, favorite status
- Media mode sends text message first, then media as reply (was media-only)
- Search/find/person/place resolve asset public URLs from tracked albums'
  shared links (share/{key}/photos/{id})
- Albums/summary commands include album public_url in context
- Enriched command template preview sample context with public_url, city,
  country, is_favorite
- Extract sanitizePreview to shared lib/sanitize.ts
- Command template preview now renders HTML links (was raw text)
- Global provider filter moved above search in sidebar
- CLAUDE.md: template consistency + context variable sync rules
This commit is contained in:
2026-03-24 16:48:57 +03:00
parent f90cc36ebd
commit d0bc767e98
26 changed files with 253 additions and 116 deletions
@@ -8,10 +8,12 @@ from typing import Any
import aiohttp
from notify_bridge_core.providers.immich.asset_utils import get_public_url
from ...database.models import ServiceProvider, TelegramBot
from ...services import make_immich_provider
from ..handler import _get_notification_trackers_for_providers, _render_cmd_template
from .common import _format_assets
from .common import _format_assets, build_asset_dict
_LOGGER = logging.getLogger(__name__)
@@ -35,19 +37,28 @@ async def _cmd_albums(
if not album_ids:
continue
results = await asyncio.gather(
ext_domain = (provider.config.get("external_domain") or provider.config.get("url", "")).rstrip("/")
album_results = await asyncio.gather(
*[immich.client.get_album(aid) for aid in album_ids],
return_exceptions=True,
)
for album_id, result in zip(album_ids, results):
link_results = await asyncio.gather(
*[immich.client.get_shared_links(aid) for aid in album_ids],
return_exceptions=True,
)
for album_id, result, links in zip(album_ids, album_results, link_results):
if isinstance(result, Exception):
_LOGGER.warning("Failed to fetch album %s: %s", album_id, result)
albums_data.append({
"name": f"{album_id[:8]}...", "asset_count": "?", "id": album_id,
})
elif result:
pub_url = ""
if not isinstance(links, Exception) and ext_domain:
pub_url = get_public_url(ext_domain, links) or ""
albums_data.append({
"name": result.name, "asset_count": result.asset_count, "id": album_id,
"name": result.name, "asset_count": result.asset_count,
"id": album_id, "public_url": pub_url,
})
return {"albums": albums_data}
@@ -77,10 +88,7 @@ async def cmd_favorites(
if result:
for aid, asset in list(result.assets.items())[:50]:
if asset.is_favorite and len(fav_assets) < count:
fav_assets.append({
"id": asset.id, "originalFileName": asset.filename,
"type": asset.type,
})
fav_assets.append(build_asset_dict(asset))
if len(fav_assets) >= count:
break
@@ -90,24 +98,34 @@ async def cmd_favorites(
async def cmd_summary(
client: Any, all_album_ids: list[str], locale: str,
cmd_templates: dict[str, dict[str, str]],
external_domain: str = "",
) -> str:
"""Handle /summary command with concurrent album fetching."""
if not all_album_ids:
return _render_cmd_template(cmd_templates, "summary", locale, {"albums": []})
results = await asyncio.gather(
album_results = await asyncio.gather(
*[client.get_album(aid) for aid in all_album_ids],
return_exceptions=True,
)
link_results = await asyncio.gather(
*[client.get_shared_links(aid) for aid in all_album_ids],
return_exceptions=True,
)
ext = external_domain.rstrip("/")
albums_data: list[dict] = []
for album_id, result in zip(all_album_ids, results):
for album_id, result, links in zip(all_album_ids, album_results, link_results):
if isinstance(result, Exception):
_LOGGER.warning("Failed to fetch album %s: %s", album_id, result)
continue
if result:
pub_url = ""
if not isinstance(links, Exception) and ext:
pub_url = get_public_url(ext, links) or ""
albums_data.append({
"name": result.name, "asset_count": result.asset_count, "id": album_id,
"name": result.name, "asset_count": result.asset_count,
"id": album_id, "public_url": pub_url,
})
return _render_cmd_template(cmd_templates, "summary", locale, {"albums": albums_data})