Ajoute le support d'un jeton d'accès pour les serveurs ntfy protégés

Certains serveurs ntfy auto-hébergés (ex: ntfy.arkel.fr) renvoient
403 Forbidden sans authentification. Un nouveau champ "Jeton d'accès"
(optionnel, type password) sur /settings permet de renseigner un token
qui sera envoyé comme "Authorization: Bearer ..." à chaque publication,
pour les rappels réels comme pour le bouton de test. La page /aide
documente le cas 403 et la marche à suivre.

💘 Generated with Crush

Assisted-by: Crush:glm-5.2
This commit is contained in:
Jacquin Antoine
2026-07-20 00:01:12 +02:00
parent 2ee317a46e
commit 076b5a4fa2
6 changed files with 101 additions and 8 deletions

View File

@ -11,11 +11,14 @@ logger = logging.getLogger("pointeuse.notifications")
CHECK_INTERVAL_SECONDS = 300
def send_ntfy(server: str, topic: str, message: str, title: str, user_id: str | None = None) -> bool:
def send_ntfy(server: str, topic: str, message: str, title: str, user_id: str | None = None, token: str = "") -> bool:
headers = {"Title": title.encode("utf-8"), "Priority": "high"}
if token:
headers["Authorization"] = f"Bearer {token}"
req = urllib.request.Request(
f"{server}/{topic}",
data=message.encode("utf-8"),
headers={"Title": title.encode("utf-8"), "Priority": "high"},
headers=headers,
method="POST",
)
try:
@ -43,6 +46,7 @@ async def check_user(user_id: str, now: datetime):
notif = load_notif_config(user_id)
topic = notif.get("ntfy_topic")
server = notif.get("ntfy_server", "https://ntfy.sh")
token = notif.get("ntfy_token", "")
debut_h = notif.get("rappel_debut_h", 7)
fin_h = notif.get("rappel_fin_h", 20)
if not topic:
@ -64,14 +68,14 @@ async def check_user(user_id: str, now: datetime):
await asyncio.to_thread(
send_ntfy, server, topic,
"Tu es dans les locaux mais pas encore pointé ce matin.",
"⏰ Pense à pointer", user_id,
"⏰ Pense à pointer", user_id, token,
)
elif not presence.get("present") and jour.get("matin_entree") and not jour.get("aprem_sortie"):
logger.info("rappel 'pense à dépointer' pour %r", user_id)
await asyncio.to_thread(
send_ntfy, server, topic,
"Tu as quitté les locaux sans dépointer la sortie.",
"⏰ Pense à dépointer", user_id,
"⏰ Pense à dépointer", user_id, token,
)