telegram. Making more detailed logic of notification. Slight refactoring.
This commit is contained in:
parent
1807424586
commit
8cb5b4733a
|
@ -9,6 +9,26 @@ class Notifier:
|
||||||
def __init__(self, token: str):
|
def __init__(self, token: str):
|
||||||
self.bot = telebot.TeleBot(token)
|
self.bot = telebot.TeleBot(token)
|
||||||
|
|
||||||
def notify(self, chat_id: int):
|
def send_updates(self, chat_id: int, updates: list):
|
||||||
"""Send notification to the user"""
|
"""Send notification about new items to the user"""
|
||||||
self.bot.send_message(chat_id=chat_id, text="Notification stub")
|
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']}"
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in a new issue