Skip to main content

Crate ferro_notifications

Crate ferro_notifications 

Source
Expand description

§Ferro Notifications

Multi-channel notification system for the Ferro 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 ferro_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.
InAppConfig
In-app SSE channel configuration.
InAppMessage
An in-app notification message.
MailAttachment
A binary attachment for a mail message.
MailConfig
Mail configuration supporting multiple drivers.
MailMessage
A mail message for email notifications.
NotificationConfig
Configuration for the notification dispatcher.
NotificationDispatcher
The notification dispatcher.
PushMessage
Placeholder push notification. Shape will be finalized when an APNs/FCM adapter ships.
ResendConfig
Resend-specific configuration.
SlackAttachment
A Slack message attachment.
SlackField
A field within a Slack attachment.
SlackMessage
A Slack message for webhook notifications.
SmsMessage
Placeholder SMS message. Shape will be finalized when an SMS adapter ships.
SmtpConfig
SMTP-specific configuration.
StoredNotification
A notification stored in the database.
WhatsAppMessage
A WhatsApp message wrapping the typed shape from ferro-whatsapp.

Enums§

Channel
Available notification channels.
Error
Errors that can occur during notification dispatch.
InAppSeverity
Severity hint for in-app notification rendering.
MailDriver
Mail transport driver.

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.