msflib.notifications¶
Public modules of the msflib-notifications package.
msflib.notifications.actions
¶
AccountNotificationAction
¶
Bases: ModelAction[AccountNotification, AccountNotificationCreate, AccountNotificationUpdate]
save_for_recipients(session: Session, notification: Notification, recipients: list[AccountBase] | None = None) -> list[AccountNotification]
¶
Create account-notification links for already-resolved account recipients.
mark_one(session: Session, notification_id: int, owner: AccountBase, status: bool | None = None) -> AccountNotification | None
¶
Mark single notifications for an account as read/unread.
mark_all(session: Session, owner: AccountBase, status: bool | None = None) -> list[AccountNotification]
¶
Mark all notifications for an account as read/unread.
NotificationAction
¶
Bases: ModelAction[Notification, NotificationCreate, NotificationUpdate]
create_of_type(session: Session, type: NotificationType, data: NotificationCreate, update: dict | None = None) -> Notification
¶
Create a notification of a specific type.
msflib.notifications.config
¶
msflib.notifications.models
¶
msflib.notifications.router
¶
admin_account_notification_router(get_session: Callable, get_current_account: Callable, role_check: Callable, settings: Settings, account_action: AccountAction | None = None, notification_create_type: type[Any] | None = None, prefix: str = '/admin/notifications', tags: list[str] | None = None)
¶
Create admin notification router for workspace users.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
get_session
|
Callable
|
Dependency returning a database session. |
required |
get_current_account
|
Callable
|
Dependency returning authenticated admin account. |
required |
role_check
|
Callable
|
Dependency that enforces role-based authorization. |
required |
settings
|
Settings
|
Application settings for notification handlers. |
required |
notification_create_type
|
type[Any] | None
|
Schema class used to validate the notification
request body (default: |
None
|
prefix
|
str
|
Route prefix. |
'/admin/notifications'
|
tags
|
list[str] | None
|
OpenAPI tags. |
None
|
msflib.notifications.service
¶
dispatch_account_notifications(session: Session, settings: SettingsBase, data: NotificationCreate, n_type: NotificationType, receivers: list[AccountBase] | None = None, sender: AccountBase | None = None, resolve_receivers: Callable[[list[AccountBase]], list[AccountBase]] | None = None, notification_action: NotificationAction | None = None, account_notification_action: AccountNotificationAction | None = None, handler_factory: NotificationHandlerFactory | None = None) -> Notification | None
¶
Dispatches notifications with the specified details direct to specified accounts. This dispatcher calls the various registered handlers and sends messages through them.
sms_notification(to_number: str, message: str, settings: Settings) -> str | None
¶
Sends an SMS notification using Twilio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_number
|
str
|
Phone number to send SMS to |
required |
message
|
str
|
SMS message content |
required |
settings
|
Settings
|
Application settings containing Twilio credentials |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Message SID if successful, None otherwise |
notification
¶
NotificationHandlerFactory
¶
Factory for creating notification channel handlers. This can be extended to support various channels like email, SMS, Discord, etc.
dispatch_account_notifications(session: Session, settings: SettingsBase, data: NotificationCreate, n_type: NotificationType, receivers: list[AccountBase] | None = None, sender: AccountBase | None = None, resolve_receivers: Callable[[list[AccountBase]], list[AccountBase]] | None = None, notification_action: NotificationAction | None = None, account_notification_action: AccountNotificationAction | None = None, handler_factory: NotificationHandlerFactory | None = None) -> Notification | None
¶
Dispatches notifications with the specified details direct to specified accounts. This dispatcher calls the various registered handlers and sends messages through them.
sms
¶
sms_notification(to_number: str, message: str, settings: Settings) -> str | None
¶
Sends an SMS notification using Twilio.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
to_number
|
str
|
Phone number to send SMS to |
required |
message
|
str
|
SMS message content |
required |
settings
|
Settings
|
Application settings containing Twilio credentials |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Message SID if successful, None otherwise |