feat: add Telegram notifications for user signup and Stripe events
All checks were successful
Deploy to Production / Build and Deploy (push) Successful in 2m34s

This commit is contained in:
2026-06-07 11:37:01 +02:00
parent 8659b6761f
commit 29753881a6
3 changed files with 122 additions and 0 deletions

37
utils/telegram.py Normal file
View File

@@ -0,0 +1,37 @@
import os
import logging
import httpx
logger = logging.getLogger(__name__)
async def send_telegram_notification(message: str) -> bool:
"""
Envoie un message formaté en Markdown à l'administrateur via Telegram.
Utilise les variables d'environnement TELEGRAM_BOT_TOKEN et TELEGRAM_CHAT_ID.
"""
bot_token = os.getenv("TELEGRAM_BOT_TOKEN")
chat_id = os.getenv("TELEGRAM_CHAT_ID")
if not bot_token or not chat_id:
logger.warning("Notification Telegram ignorée : TELEGRAM_BOT_TOKEN ou TELEGRAM_CHAT_ID non configuré.")
return False
url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
payload = {
"chat_id": chat_id,
"text": message,
"parse_mode": "Markdown"
}
try:
async with httpx.AsyncClient(timeout=10.0) as client:
resp = await client.post(url, json=payload)
if resp.status_code == 200:
logger.info("Notification Telegram envoyée avec succès.")
return True
else:
logger.error(f"Échec de l'envoi Telegram (HTTP {resp.status_code}): {resp.text}")
return False
except Exception as e:
logger.error(f"Erreur lors de l'envoi de la notification Telegram : {e}")
return False