From c0148c2c91b46e26875d6e4cd2f053307d391528 Mon Sep 17 00:00:00 2001 From: Alexey Skobkin Date: Mon, 2 May 2022 23:41:17 +0300 Subject: [PATCH] #7 Making more detailed logic of notification. Slight refactoring. --- telegram/notifier.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/telegram/notifier.py b/telegram/notifier.py index 9abdc55..d80dfc9 100644 --- a/telegram/notifier.py +++ b/telegram/notifier.py @@ -9,6 +9,26 @@ class Notifier: def __init__(self, token: str): self.bot = telebot.TeleBot(token) - def notify(self, chat_id: int): - """Send notification to the user""" - self.bot.send_message(chat_id=chat_id, text="Notification stub") + def send_updates(self, chat_id: int, updates: list): + """Send notification about new items to the user""" + for update in updates: + self.__send_update(chat_id, update) + + def __send_update(self, chat_id: int, update): + self.bot.send_message( + chat_id=chat_id, + text=self.__format_message(), + parse_mode='MarkdownV2' + ) + + def __format_message(self) -> str: + update = { + 'title': 'Item Title', + 'text': 'Short item text here...', + 'url': 'https://fediland.github.io/', + } + + return ( + f"**[{update['title']}]({update['url']})**\n\n" + f"{update['text']}" + )