feat: Enhance hook management and session handling

- Update hook model to include last_triggered_at field.
- Modify API endpoints to support updating hooks with new fields.
- Implement session management UI improvements with toggle functionality.
- Add new JavaScript functions for better session detail visibility.
- Refactor hook storage logic to handle last triggered timestamps.
- Introduce new favicon and logo for branding.
- Update styles for improved layout and user experience.
- Enhance tests to cover new functionality and ensure reliability.
This commit is contained in:
Andre Beging
2025-10-07 13:39:07 +02:00
parent c7f694d820
commit 1204f5dcde
11 changed files with 559 additions and 134 deletions

View File

@@ -10,7 +10,7 @@ from .config import get_settings
from .models import (
HookCreate,
HookResponse,
HookUpdateId,
HookUpdate,
LoginStartRequest,
LoginVerifyRequest,
MessageTriggerResponse,
@@ -21,7 +21,8 @@ from .storage import (
delete_hook_async,
get_hook_async,
list_hooks_async,
update_hook_id_async,
record_hook_trigger_async,
update_hook_async,
)
from .telegram_service import telegram_service
@@ -128,6 +129,7 @@ async def list_hooks() -> List[HookResponse]:
chat_id=hook.chat_id,
message=hook.message,
created_at=hook.created_at,
last_triggered_at=hook.last_triggered_at,
action_url=f"{settings.base_url}{hook.action_path}",
)
for hook in hooks
@@ -142,6 +144,7 @@ async def create_hook(payload: HookCreate) -> HookResponse:
chat_id=hook.chat_id,
message=hook.message,
created_at=hook.created_at,
last_triggered_at=hook.last_triggered_at,
action_url=f"{settings.base_url}{hook.action_path}",
)
@@ -154,9 +157,14 @@ async def delete_hook(hook_id: str) -> None:
@app.patch("/api/hooks/{hook_id}", response_model=HookResponse)
async def update_hook(hook_id: str, payload: HookUpdateId) -> HookResponse:
async def update_hook(hook_id: str, payload: HookUpdate) -> HookResponse:
try:
updated = await update_hook_id_async(hook_id, payload.hook_id)
updated = await update_hook_async(
hook_id,
new_hook_id=payload.hook_id,
chat_id=payload.chat_id,
message=payload.message,
)
except KeyError as exc:
raise HTTPException(status_code=404, detail="Hook not found") from exc
except ValueError as exc:
@@ -166,6 +174,7 @@ async def update_hook(hook_id: str, payload: HookUpdateId) -> HookResponse:
chat_id=updated.chat_id,
message=updated.message,
created_at=updated.created_at,
last_triggered_at=updated.last_triggered_at,
action_url=f"{settings.base_url}{updated.action_path}",
)
@@ -181,4 +190,5 @@ async def trigger_hook(hook_id: str) -> MessageTriggerResponse:
raise HTTPException(status_code=401, detail=str(exc)) from exc
except Exception as exc: # noqa: BLE001
raise HTTPException(status_code=500, detail=str(exc)) from exc
await record_hook_trigger_async(hook.hook_id)
return MessageTriggerResponse(status="sent", hook_id=hook.hook_id, chat_id=hook.chat_id)