Files
awoooi/apps/api/src/routes/notifications.py
OG T 196d269b92 feat: add all application source code
- apps/api: FastAPI backend with Dockerfile
- apps/web: Next.js frontend with Dockerfile
- apps/sensor: Signal collection agent
- packages: shared packages

Co-Authored-By: Claude <noreply@anthropic.com>
2026-03-22 18:57:44 +08:00

74 lines
1.7 KiB
Python

"""
Notification Endpoints
"""
from datetime import datetime
from typing import Literal
from uuid import UUID, uuid4
from fastapi import APIRouter
from pydantic import BaseModel
router = APIRouter()
class NotificationChannel(BaseModel):
id: str
type: Literal["telegram", "slack", "line", "email", "discord", "webhook"]
name: str
enabled: bool
class NotificationRequest(BaseModel):
channel_id: str
message: str
template_id: str | None = None
variables: dict | None = None
priority: Literal["low", "normal", "high", "urgent"] = "normal"
class NotificationResult(BaseModel):
id: UUID
status: Literal["queued", "sent", "failed"]
sent_at: datetime | None = None
error: str | None = None
# Mock channels
MOCK_CHANNELS: list[NotificationChannel] = [
NotificationChannel(
id="telegram-ops",
type="telegram",
name="Ops Team",
enabled=True,
),
NotificationChannel(
id="slack-alerts",
type="slack",
name="Alerts Channel",
enabled=True,
),
NotificationChannel(
id="email-oncall",
type="email",
name="On-Call Email",
enabled=True,
),
]
@router.get("/channels", response_model=list[NotificationChannel])
async def list_notification_channels() -> list[NotificationChannel]:
"""列出通知頻道"""
return MOCK_CHANNELS
@router.post("/send", response_model=NotificationResult, status_code=202)
async def send_notification(request: NotificationRequest) -> NotificationResult:
"""發送通知"""
# TODO: 實際發送通知
return NotificationResult(
id=uuid4(),
status="queued",
)