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§
- Channel
Result - Result of sending a notification through a channel.
- Database
Message - A database message for in-app notifications.
- Mail
Config - SMTP mail configuration.
- Mail
Message - A mail message for email notifications.
- Notification
Config - Configuration for the notification dispatcher.
- Notification
Dispatcher - The notification dispatcher.
- Slack
Attachment - A Slack message attachment.
- Slack
Field - A field within a Slack attachment.
- Slack
Message - A Slack message for webhook notifications.
- Stored
Notification - A notification stored in the database.
Enums§
Traits§
- Database
Notification Store - 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.