# telegram_utils.py import sys import os sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) import aiohttp import logging from telegram import Bot from telegram.constants import ParseMode from config import TELEGRAM_BOT_TOKEN, DEVELOPER_CHAT_ID, BOT_NAME # Initialize Telegram Bot # Create a custom connection pool conn_pool = aiohttp.TCPConnector(limit=100) # Increase the connection limit timeout = aiohttp.ClientTimeout(total=30) # Set a longer timeout # bot = Bot(TELEGRAM_BOT_TOKEN) # , request=aiohttp.ClientSession(connector=conn_pool, timeout=timeout).request) bot = Bot(token=TELEGRAM_BOT_TOKEN) async def send_telegram_message(message): try: await bot.send_message(chat_id=DEVELOPER_CHAT_ID, text=f"[{BOT_NAME}] {message}", parse_mode=ParseMode.HTML) logging.info(f"Telegram message sent: {message}") except Exception as e: logging.error(f"Error sending Telegram message: {str(e)}") # You can add more Telegram-related functions here if needed