feat: Enable (or not) email or Telegram notifications
This commit is contained in:
@@ -2,6 +2,10 @@
|
||||
CROSSFIT_USERNAME=Kevin8407
|
||||
CROSSFIT_PASSWORD=9vx03OSE
|
||||
|
||||
# Notification settings
|
||||
ENABLE_EMAIL_NOTIFICATIONS=true
|
||||
ENABLE_TELEGRAM_NOTIFICATIONS=true
|
||||
|
||||
EMAIL_FROM=kevin@mistergeek.fr
|
||||
EMAIL_TO=kbataille@vivaldi.net
|
||||
EMAIL_PASSWORD=
|
||||
|
||||
@@ -97,7 +97,16 @@ class CrossFitBooker:
|
||||
"chat_id": os.environ.get("TELEGRAM_CHAT_ID")
|
||||
}
|
||||
|
||||
self.notifier = SessionNotifier(email_credentials, telegram_credentials)
|
||||
# Get notification settings from environment variables
|
||||
enable_email = os.environ.get("ENABLE_EMAIL_NOTIFICATIONS", "true").lower() in ("true", "1", "yes")
|
||||
enable_telegram = os.environ.get("ENABLE_TELEGRAM_NOTIFICATIONS", "true").lower() in ("true", "1", "yes")
|
||||
|
||||
self.notifier = SessionNotifier(
|
||||
email_credentials,
|
||||
telegram_credentials,
|
||||
enable_email=enable_email,
|
||||
enable_telegram=enable_telegram
|
||||
)
|
||||
|
||||
def get_auth_headers(self) -> Dict[str, str]:
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import smtplib
|
||||
import os
|
||||
from email.message import EmailMessage
|
||||
from telegram import Bot
|
||||
|
||||
@@ -12,18 +13,24 @@ class SessionNotifier:
|
||||
(e.g., 'from', 'to', 'password')
|
||||
telegram_credentials (dict): Dictionary containing Telegram credentials
|
||||
(e.g., 'token', 'chat_id')
|
||||
enable_email (bool): Whether to enable email notifications
|
||||
enable_telegram (bool): Whether to enable Telegram notifications
|
||||
"""
|
||||
|
||||
def __init__(self, email_credentials, telegram_credentials):
|
||||
def __init__(self, email_credentials, telegram_credentials, enable_email=True, enable_telegram=True):
|
||||
"""
|
||||
Initialize the SessionNotifier with email and Telegram credentials.
|
||||
|
||||
Args:
|
||||
email_credentials (dict): Email credentials for authentication
|
||||
telegram_credentials (dict): Telegram credentials for authentication
|
||||
enable_email (bool): Whether to enable email notifications
|
||||
enable_telegram (bool): Whether to enable Telegram notifications
|
||||
"""
|
||||
self.email_credentials = email_credentials
|
||||
self.telegram_credentials = telegram_credentials
|
||||
self.enable_email = enable_email
|
||||
self.enable_telegram = enable_telegram
|
||||
|
||||
def send_email_notification(self, message):
|
||||
"""
|
||||
@@ -71,6 +78,9 @@ class SessionNotifier:
|
||||
email_message = f"Session booked: {session_details}"
|
||||
telegram_message = f"Session booked: {session_details}"
|
||||
|
||||
# Send notifications through both channels
|
||||
self.send_email_notification(email_message)
|
||||
self.send_telegram_notification(telegram_message)
|
||||
# Send notifications through enabled channels
|
||||
if self.enable_email:
|
||||
self.send_email_notification(email_message)
|
||||
|
||||
if self.enable_telegram:
|
||||
self.send_telegram_notification(telegram_message)
|
||||
Reference in New Issue
Block a user