import asyncio # Telegram library is async import logging import telegram logger = logging.getLogger(__name__) # Set the logger name, to the name of the module class TelegramNotifier: def __init__(self, token: str, chat_id: int): self.chat_id: int = chat_id self.bot = telegram.Bot(token) async def async_send_message(self, text): async with self.bot: await self.bot.send_message(text=text, chat_id=self.chat_id, parse_mode=telegram.constants.ParseMode.MARKDOWN) # Send message from non async function def send_message(self, text): logger.debug(f"Sending message: {text}") asyncio.run(self.async_send_message(text))