send message async

This commit is contained in:
Omar Sánchez Pizarro
2023-10-09 14:55:54 +02:00
parent 4f1aea3139
commit 6020ce5acb
5 changed files with 9 additions and 8 deletions

View File

@@ -1,5 +1,5 @@
import telegram
from app import config_parser
import telegram
config = config_parser.ConfigParser().loadConfig()
@@ -7,8 +7,7 @@ config = config_parser.ConfigParser().loadConfig()
class telegramBot:
bot = None
def __init__(self):
self.bot = telegram.Bot(token=config['telegram']['token'])
def sendMessage(self, message):
self.bot.sendMessage(chat_id=config['telegram']['chat_id'], text=str(message), parse_mode=telegram.ParseMode.HTML)
async def sendMessage(self, message):
self.bot = telegram.Bot(config['telegram']['token'])
async with self.bot:
await self.bot.sendMessage(chat_id=config['telegram']['chat_id'], text=str(message))