import asyncio import logging import telegram logger = logging.getLogger(__name__) # Set the logger name, to the name of the module class Telegram: def __init__(self, config: dict): self.config: dict = config self.bot = telegram.Bot(config['token']) asyncio.run(self.init_bot()) def send_message(self, text): asyncio.run(self.async_send_message(text)) async def async_send_message(self, text): async with self.bot: await self.bot.send_message(text=text, chat_id=self.config['chat_id']) async def init_bot(self): async with self.bot: logger.debug(f'Telegram bot initialized {await self.bot.get_me()}')