Notification Service & Delivery

Notification Service & Delivery

The NotificationService is the central orchestrator for all notifications in NexusRMS. It creates notification records, determines delivery channels, respects user preferences and quiet hours, and dispatches through multiple channels including in-app, email, SMS, and push.

NotificationService Methods

MethodDescription
send(user, type, data, options)Creates a notification record and triggers delivery across all enabled channels for the user
sendToMany(users, type, data)Bulk sends the same notification to multiple users efficiently
getFeed(user, perPage=20, filters)Returns a paginated notification feed with optional type, read status, and date filters
getUnreadCount(user)Returns the count of unread notifications for badge display
getRecent(user, limit=10)Returns the latest notifications for the dropdown panel
groupNotifications(notifications)Groups related notifications by group_key (e.g. "3 new comments on Project #412")
processSnoozedNotifications()Cron job that delivers snoozed notifications once quiet hours end
sendPlatformAnnouncement(data)Broadcasts a system-wide announcement to all connected users
getStatistics(user, start, end)Returns notification statistics for a given date range

Notification Model Fields

FieldTypeDescription
user_idintegerThe recipient user
typestringNotification type (e.g. project.created, invoice.overdue)
notifiable_typestringPolymorphic model class
notifiable_idintegerPolymorphic model ID
titlestringDisplay title
bodytextNotification body text
iconstringMDI icon name
colorstringVuetify colour name
dataJSONContains action_url, priority, and action_label
group_keystringGroups related notifications together
thread_idstringLinks to a discussion thread
is_groupedbooleanWhether this notification has been collapsed into a group
read_attimestampWhen the notification was read (null if unread)
archived_attimestampWhen the notification was archived
snoozed_untiltimestampDelivery deferred until this time
channelsarrayDelivery channels used (in_app, email, sms, push)
email_sent_attimestampWhen the email was dispatched
email_opened_attimestampWhen the email tracking pixel was loaded
sms_sent_attimestampWhen the SMS was dispatched
push_sent_attimestampWhen the push notification was sent

Notification Actions

  • markAsRead — sets read_at to the current timestamp
  • markAsUnread — clears read_at back to null
  • archive — sets archived_at, removing the notification from the active feed
  • unarchive — clears archived_at, restoring the notification to the feed
  • snooze(until) — sets snoozed_until to defer delivery to a future time
  • isSnoozed — returns true if snoozed_until is in the future

Computed Attributes

  • time_ago — human-readable relative timestamp (e.g. "5 minutes ago")
  • action_url — extracted from the data JSON, links to the relevant resource
  • action_label — button text, defaults to "View" if not specified
  • priority — extracted from data JSON, defaults to "normal"

Query Scopes

  • unread() — where read_at is null
  • read() — where read_at is not null
  • archived() — where archived_at is not null
  • active() — not archived and not currently snoozed
  • ofType(type) — filters by notification type prefix

NotificationDeliveryService

The delivery service orchestrates multi-channel dispatch while respecting user preferences:

  1. In-app — broadcasts via WebSocket using the NotificationCreated event for instant display
  2. Email — dispatched immediately or batched into a digest depending on user preference (handled by EmailNotificationService)
  3. SMS — sent via Twilio for high and urgent priority notifications only (handled by SMSNotificationService)
  4. Push — browser push notifications and PWA push for mobile devices (handled by PushNotificationService)

Priority Levels

PriorityColourBehaviour
UrgentError redBypasses quiet hours, triggers all enabled channels immediately
HighWarning orangeRespects quiet hours, triggers all enabled channels
NormalPrimary blueRespects quiet hours, standard delivery
LowInfo light blueRespects quiet hours, in-app only unless user opts in

Was this article helpful?