summaryrefslogtreecommitdiff
path: root/src/telegram_notifier.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/telegram_notifier.py')
-rw-r--r--src/telegram_notifier.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/telegram_notifier.py b/src/telegram_notifier.py
new file mode 100644
index 0000000..870bf6c
--- /dev/null
+++ b/src/telegram_notifier.py
@@ -0,0 +1,22 @@
+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))