feat: Enable (or not) email or Telegram notifications
This commit is contained in:
@@ -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