diff options
| author | user <user@node5.net> | 2024-02-27 20:25:42 +0100 |
|---|---|---|
| committer | user <user@node5.net> | 2024-02-27 20:25:42 +0100 |
| commit | efeb7e086c5b8ba45745851223d6b26962d0740a (patch) | |
| tree | 2da6617586a6baa7f4871bcda2f80032da0254f2 /src/telegram_handler.py | |
| parent | 730c3e19e39c1245eb1d44536fa8b5db1ce1f563 (diff) | |
telegram bot on comment
Diffstat (limited to 'src/telegram_handler.py')
| -rw-r--r-- | src/telegram_handler.py | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/telegram_handler.py b/src/telegram_handler.py new file mode 100644 index 0000000..0484e9b --- /dev/null +++ b/src/telegram_handler.py @@ -0,0 +1,27 @@ +import asyncio +import os + +import telegram +import yaml + +with open(os.path.join('configs', 'telegram.yml'), 'r') as file: + config = yaml.safe_load(file.read()) + +bot = telegram.Bot(config['token']) + + +def send_message(text): + asyncio.run(async_send_message(text)) + + +async def async_send_message(text): + async with bot: + await bot.send_message(text=text, chat_id=config['chat_id']) + + +async def init_bot(): + async with bot: + print(await bot.get_me()) + + +asyncio.run(init_bot()) |
