#7 Notifier is now considering Telegram API sendMessage() rate limit.
This commit is contained in:
parent
3bffd32df0
commit
f9ffdac38a
13
telegram.py
13
telegram.py
|
@ -1,3 +1,5 @@
|
|||
import time
|
||||
|
||||
from telebot import TeleBot
|
||||
from telebot.handler_backends import BaseMiddleware
|
||||
from telebot.types import Message
|
||||
|
@ -88,13 +90,22 @@ class CommandProcessor:
|
|||
class Notifier:
|
||||
"""Sends notifications to users about new RSS feed items."""
|
||||
|
||||
BATCH_LIMIT: int = 30
|
||||
|
||||
sent_counter: int = 0
|
||||
|
||||
def __init__(self, token: str):
|
||||
self.bot: TeleBot = TeleBot(token)
|
||||
|
||||
def send_updates(self, chat_id: int, updates: list[FeedItem]):
|
||||
def send_updates(self, chat_ids: list[int], updates: list[FeedItem]):
|
||||
"""Send notification about new items to the user"""
|
||||
for chat_id in chat_ids:
|
||||
for update in updates:
|
||||
self.__send_update(chat_id, update)
|
||||
self.sent_counter += 1
|
||||
if self.sent_counter >= self.BATCH_LIMIT:
|
||||
# TODO: probably implement better later
|
||||
time.sleep(1)
|
||||
|
||||
def __send_update(self, telegram_id: int, update: FeedItem):
|
||||
self.bot.send_message(
|
||||
|
|
Loading…
Reference in a new issue