remove fallback telegram chat id

This commit is contained in:
Shihaam Abdul Rahman 2024-09-21 06:09:14 +05:00
parent bf1c6688a8
commit 0f45896d79
Signed by: shihaam
GPG Key ID: 6DA2E87EBC227636
2 changed files with 18 additions and 18 deletions

View File

@ -1,5 +1,4 @@
TELEGRAM_API_KEY=''
TELEGRAM_CHAT_ID=''
TELEGRAM_DOMAIN='telegram.local'

View File

@ -14,7 +14,6 @@ logger = logging.getLogger(__name__)
# Configuration
TELEGRAM_API_KEY = os.getenv('TELEGRAM_API_KEY')
DEFAULT_CHAT_ID = os.getenv('TELEGRAM_CHAT_ID') # Fallback chat ID
NTFY_TOKEN = os.getenv('NTFY_TOKEN')
NTFY_URL = os.getenv('NTFY_URL')
TELEGRAM_DOMAIN = os.getenv('TELEGRAM_DOMAIN', 'telegram.local')
@ -71,10 +70,14 @@ class SMTPHandler:
logger.info(f"Matched ntfy pattern: {ntfy_match.group(1)}")
return ntfy_match.group(1), 'ntfy'
logger.warning(f"Invalid email format: {email}. Using default Telegram chat ID.")
return DEFAULT_CHAT_ID, 'telegram'
logger.error(f"Invalid email format: {email}. Unable to determine service.")
return None, None
async def send_telegram(self, chat_id, message):
if not chat_id:
logger.error("No valid Telegram chat ID provided. Message not sent.")
return
logger.info(f"Sending message to Telegram chat ID: {chat_id}")
bot = telegram.Bot(TELEGRAM_API_KEY)
try:
@ -82,14 +85,12 @@ class SMTPHandler:
logger.info(f"Message sent successfully to Telegram chat ID: {chat_id}")
except telegram.error.BadRequest as e:
logger.error(f"Failed to send message to Telegram chat ID: {chat_id}. Error: {str(e)}")
logger.info("Attempting to send to default Telegram chat ID.")
try:
await bot.send_message(chat_id=DEFAULT_CHAT_ID, text=message)
logger.info(f"Message sent successfully to default Telegram chat ID: {DEFAULT_CHAT_ID}")
except telegram.error.BadRequest as e:
logger.error(f"Failed to send message to default Telegram chat ID. Error: {str(e)}")
async def send_ntfy(self, topic, subject, body):
if not topic:
logger.error("No valid ntfy topic provided. Message not sent.")
return
logger.info(f"Sending message to ntfy topic: {topic}")
headers = {
"Authorization": f"Bearer {NTFY_TOKEN}",