fix support for channels and supergroups

This commit is contained in:
Shihaam Abdul Rahman 2024-09-21 02:12:35 +05:00
parent e59560fafd
commit 358b50857e
Signed by: shihaam
GPG Key ID: 6DA2E87EBC227636

View File

@ -1,4 +1,4 @@
import os
kimport os
import asyncio
from aiosmtpd.controller import Controller
from email.parser import BytesParser
@ -35,14 +35,15 @@ class SMTPHandler:
try:
await bot.send_message(chat_id=chat_id, text=telegram_message)
print(f"Message sent to Telegram chat ID: {chat_id}")
except telegram.error.BadRequest:
print(f"Failed to send message to chat ID: {chat_id}. Using default chat ID.")
except telegram.error.BadRequest as e:
print(f"Failed to send message to chat ID: {chat_id}. Error: {str(e)}")
print("Attempting to send to default chat ID.")
await bot.send_message(chat_id=DEFAULT_CHAT_ID, text=telegram_message)
return '250 Message accepted for delivery'
def extract_chat_id(self, email):
match = re.match(r'(\d+)@telegram-relay\.local', email)
match = re.match(r'(-?\d+)@telegram-relay\.local', email)
if match:
return match.group(1)
print(f"Invalid email format: {email}. Using default chat ID.")
@ -56,4 +57,4 @@ if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.create_task(start_smtp_server())
print(f"SMTP server started on {SMTP_HOST}:{SMTP_PORT}")
loop.run_forever()
loop.run_forever(