Source code for ppc_robot_lib.notifications.abstract_adapter

from abc import ABC, abstractmethod
from datetime import datetime
from typing import Any
from ppc_robot_lib import models
import celery


[docs] class AbstractNotificationAdapter(ABC): """ Abstract notification adapter. The implementing class should send notifications through the defined channel. """ @abstractmethod def __init__(self, celery_app: 'celery.Celery', configuration: dict[str, Any]): """ Initializes the adapter for channel with given configuration. :param configuration: Channel configuration. """ self.celery_app = celery_app self.configuration = configuration
[docs] @classmethod @abstractmethod def supports_summary(cls) -> bool: """ Returns whether the implementing adapter supports sending daily summaries. :return: True if the adapter supports daily summaries. """ return False
[docs] @abstractmethod def send_notifications(self, user_id: int, notifications: list['models.Notification']): """ Queues notification over the given channel. The implementing class should decide whether the notification shall be sent, according to the specifics of the given channel. :param int user_id: User which should receive the notification. :param list[Notification] notifications: Notification to send. """ pass
[docs] def send_summary(self, user_id: int, last_at: datetime, enabled_categories: list[int] = None): """ Creates and sends daily summary over the given channel. The implementing class should decide which notifications shall be sent in the summary. :param int user_id: User for which the summary should be generated. :param datetime last_at: Time when the last summary was sent. :param enabled_categories: List of enabled notification categories. """ pass