Compare commits

..

2 Commits

2 changed files with 18 additions and 1 deletions

View File

@@ -5,6 +5,7 @@ CROSSFIT_PASSWORD=your_password
# Notification settings
ENABLE_EMAIL_NOTIFICATIONS=true
ENABLE_TELEGRAM_NOTIFICATIONS=true
NOTIFY_IMPOSSIBLE_BOOKING=false
# Email notification credentials
SMTP_SERVER=mail.infomaniak.com

View File

@@ -34,6 +34,9 @@ class SessionNotifier:
self.enable_email = enable_email
self.enable_telegram = enable_telegram
# Check environment variable for impossible booking notifications
self.notify_impossible = os.environ.get("NOTIFY_IMPOSSIBLE_BOOKING", "true").lower() in ("true", "1", "yes")
def send_email_notification(self, message):
"""
Send an email notification with the given message.
@@ -121,13 +124,26 @@ class SessionNotifier:
if self.enable_telegram:
await self.send_telegram_notification(telegram_message)
async def notify_impossible_booking(self, session_details):
async def notify_impossible_booking(self, session_details, notify_if_impossible=None):
"""
Notify about an impossible session booking via email and Telegram.
Args:
session_details (str): Details about the session that couldn't be booked
notify_if_impossible (bool, optional): Whether to send notifications for impossible bookings.
If None, uses the value from the NOTIFY_IMPOSSIBLE_BOOKING
environment variable.
"""
# Determine if notifications should be sent
# First check the method parameter (if provided), then the environment variable
should_notify = (
notify_if_impossible if notify_if_impossible is not None else self.notify_impossible
)
# Only proceed if notifications for impossible bookings are enabled
if not should_notify:
return
# Create messages for both email and Telegram
email_message = f"Failed to book session: {session_details}"
telegram_message = f"Failed to book session: {session_details}"