Crate ferro_notifications

Crate ferro_notifications 

Source
Expand description

§Cancer Notifications

Multi-channel notification system for the Cancer framework.

Provides a Laravel-inspired notification system with support for:

  • Mail notifications via SMTP
  • Database notifications for in-app delivery
  • Slack webhook notifications

§Example

use cancer_notifications::{Notification, Notifiable, Channel, MailMessage};

// Define a notification
struct OrderShipped {
    order_id: i64,
    tracking: String,
}

impl Notification for OrderShipped {
    fn via(&self) -> Vec<Channel> {
        vec![Channel::Mail, Channel::Database]
    }

    fn to_mail(&self) -> Option<MailMessage> {
        Some(MailMessage::new()
            .subject("Your order has shipped!")
            .body(format!("Tracking: {}", self.tracking)))
    }
}

// Make User notifiable
struct User {
    email: String,
}

impl Notifiable for User {
    fn route_notification_for(&self, channel: Channel) -> Option<String> {
        match channel {
            Channel::Mail => Some(self.email.clone()),
            _ => None,
        }
    }
}

// Send the notification
let user = User { email: "user@example.com".into() };
user.notify(OrderShipped {
    order_id: 123,
    tracking: "ABC123".into(),
}).await?;

Structs§

ChannelResult
Result of sending a notification through a channel.
DatabaseMessage
A database message for in-app notifications.
MailConfig
SMTP mail configuration.
MailMessage
A mail message for email notifications.
NotificationConfig
Configuration for the notification dispatcher.
NotificationDispatcher
The notification dispatcher.
SlackAttachment
A Slack message attachment.
SlackField
A field within a Slack attachment.
SlackMessage
A Slack message for webhook notifications.
StoredNotification
A notification stored in the database.

Enums§

Channel
Available notification channels.
Error
Errors that can occur during notification dispatch.

Traits§

DatabaseNotificationStore
Extension trait for database notification storage.
Notifiable
Trait for entities that can receive notifications.
Notification
A notification that can be sent through multiple channels.

Attribute Macros§

async_trait
Re-export async_trait for convenience.