ferro-notifications

Crates.ioferro-notifications
lib.rsferro-notifications
version0.1.71
created_at2026-01-16 17:13:33.614236+00
updated_at2026-01-17 20:04:38.888636+00
descriptionMulti-channel notification system for Ferro framework
homepage
repositoryhttps://github.com/albertogferrario/ferro
max_upload_size
id2048981
size87,361
Alberto Giancarlo Ferrario (albertogferrario)

documentation

README

ferro-notifications

Multi-channel notification system for the Ferro framework.

Features

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

Usage

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 {
    id: i64,
    email: String,
}

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

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

Slack Notifications

fn to_slack(&self) -> Option<SlackMessage> {
    Some(SlackMessage::new()
        .text("New order shipped!")
        .attachment(SlackAttachment::new()
            .title("Order Details")
            .field("Order ID", &self.order_id.to_string(), true)))
}

License

MIT

Commit count: 515

cargo fmt