|
|
|
@@ -34,6 +34,9 @@ class SessionNotifier:
|
|
|
|
self.enable_email = enable_email
|
|
|
|
self.enable_email = enable_email
|
|
|
|
self.enable_telegram = enable_telegram
|
|
|
|
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):
|
|
|
|
def send_email_notification(self, message):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Send an email notification with the given message.
|
|
|
|
Send an email notification with the given message.
|
|
|
|
@@ -121,13 +124,26 @@ class SessionNotifier:
|
|
|
|
if self.enable_telegram:
|
|
|
|
if self.enable_telegram:
|
|
|
|
await self.send_telegram_notification(telegram_message)
|
|
|
|
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.
|
|
|
|
Notify about an impossible session booking via email and Telegram.
|
|
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
Args:
|
|
|
|
session_details (str): Details about the session that couldn't be booked
|
|
|
|
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
|
|
|
|
# Create messages for both email and Telegram
|
|
|
|
email_message = f"Failed to book session: {session_details}"
|
|
|
|
email_message = f"Failed to book session: {session_details}"
|
|
|
|
telegram_message = f"Failed to book session: {session_details}"
|
|
|
|
telegram_message = f"Failed to book session: {session_details}"
|
|
|
|
|