Add presence heartbeat to keep bot showing as online

matrix-nio's AsyncClient.set_presence() is called every 60s in a
background task so Matrix clients see the bot as online. On shutdown
the bot sets itself to offline.

https://claude.ai/code/session_01DuzWyMMXvLMB4VxEwJyV4X
This commit is contained in:
Claude
2026-02-28 07:46:40 +00:00
parent aaacd0b9bf
commit e21f5dfd50
2 changed files with 36 additions and 2 deletions

View File

@@ -4,7 +4,7 @@ from contextlib import asynccontextmanager
from fastapi import FastAPI
from app.database import close_db, get_thread_root, init_db, set_thread_root
from app.matrix import THREAD_ROOT_MESSAGES, close_client, send_thread_root
from app.matrix import THREAD_ROOT_MESSAGES, close_client, send_thread_root, start_presence
from app.webhooks import router as webhook_router
logging.basicConfig(
@@ -19,6 +19,7 @@ async def lifespan(app: FastAPI):
log.info("Starting Melora")
await init_db()
await _ensure_thread_roots()
await start_presence()
log.info("Melora ready")
yield
log.info("Shutting down Melora")