about summary refs log tree commit diff
path: root/src/telegram_handler.py
diff options
context:
space:
mode:
authoruser <user@node5.net>2024-02-27 20:25:42 +0100
committeruser <user@node5.net>2024-02-27 20:25:42 +0100
commitefeb7e086c5b8ba45745851223d6b26962d0740a (patch)
tree2da6617586a6baa7f4871bcda2f80032da0254f2 /src/telegram_handler.py
parent730c3e19e39c1245eb1d44536fa8b5db1ce1f563 (diff)
telegram bot on comment
Diffstat (limited to 'src/telegram_handler.py')
-rw-r--r--src/telegram_handler.py27
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())