Add Claude AI Telegram bot enhancement (Phase 6)
Some checks failed
Validate / Hassfest (push) Has been cancelled

Integrate Claude AI into the notification system for intelligent
conversational interactions and AI-powered captions.

New modules:
- ai/service.py: Claude API client with conversation history,
  caption generation, and album activity summarization
- ai/telegram_webhook.py: Telegram webhook handler for incoming
  bot messages, routes to AI service for responses

Features:
- Conversational bot: users chat with the bot about albums
- AI captions: intelligent notification messages based on album
  context (people, locations, dates) - enabled per target via
  "ai_captions" config flag
- Album summaries: "what's new?" triggers AI-generated overview
- /start command with welcome message
- Webhook register/unregister endpoints

Architecture:
- Per-chat conversation history (in-memory, capped at 20 messages)
- Graceful degradation: AI features completely disabled without
  IMMICH_WATCHER_ANTHROPIC_API_KEY env var (zero impact)
- AI caption failure falls back to Jinja2 template rendering
- Health endpoint reports ai_enabled status

Config: IMMICH_WATCHER_ANTHROPIC_API_KEY, IMMICH_WATCHER_AI_MODEL,
IMMICH_WATCHER_AI_MAX_TOKENS

Server now has 45 API routes (was 42 after Phase 5).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-19 14:38:51 +03:00
parent 43f83acda9
commit 88ffd5d077
10 changed files with 507 additions and 9 deletions

View File

@@ -22,6 +22,7 @@ from .api.targets import router as targets_router
from .api.users import router as users_router
from .api.status import router as status_router
from .api.sync import router as sync_router
from .ai.telegram_webhook import router as telegram_ai_router
logging.basicConfig(
level=logging.DEBUG if settings.debug else logging.INFO,
@@ -71,6 +72,7 @@ app.include_router(targets_router)
app.include_router(users_router)
app.include_router(status_router)
app.include_router(sync_router)
app.include_router(telegram_ai_router)
# Serve frontend static files if available
_frontend_dist = Path(__file__).parent / "frontend"
@@ -81,7 +83,8 @@ if _frontend_dist.is_dir():
@app.get("/api/health")
async def health():
"""Health check endpoint."""
return {"status": "ok", "version": "0.1.0"}
from .ai.service import is_ai_enabled
return {"status": "ok", "version": "0.1.0", "ai_enabled": is_ai_enabled()}
def run():