Skip to main content

Notification

Trait Notification 

Source
pub trait Notification: Send + Sync {
    // Required method
    fn via(&self) -> Vec<Channel>;

    // Provided methods
    fn to_mail(&self) -> Option<MailMessage> { ... }
    fn to_database(&self) -> Option<DatabaseMessage> { ... }
    fn to_slack(&self) -> Option<SlackMessage> { ... }
    fn to_whatsapp(&self) -> Option<WhatsAppMessage> { ... }
    fn to_in_app(&self) -> Option<InAppMessage> { ... }
    fn to_sms(&self) -> Option<SmsMessage> { ... }
    fn to_push(&self) -> Option<PushMessage> { ... }
    fn notification_type(&self) -> &'static str { ... }
}
Expand description

A notification that can be sent through multiple channels.

Notifications encapsulate a message that should be delivered to users through one or more channels (mail, database, slack, etc.).

§Example

use ferro_notifications::{Notification, Channel, MailMessage, DatabaseMessage};

struct OrderShipped {
    order_id: i64,
    tracking_number: 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_number)))
    }

    fn to_database(&self) -> Option<DatabaseMessage> {
        Some(DatabaseMessage::new("order_shipped")
            .data("order_id", self.order_id)
            .data("tracking", &self.tracking_number))
    }
}

Required Methods§

Source

fn via(&self) -> Vec<Channel>

The channels this notification should be sent through.

Provided Methods§

Source

fn to_mail(&self) -> Option<MailMessage>

Convert the notification to a mail message.

Source

fn to_database(&self) -> Option<DatabaseMessage>

Convert the notification to a database message.

Source

fn to_slack(&self) -> Option<SlackMessage>

Convert the notification to a Slack message.

Source

fn to_whatsapp(&self) -> Option<WhatsAppMessage>

Convert the notification to a WhatsApp message (per CONTEXT.md D-02).

Source

fn to_in_app(&self) -> Option<InAppMessage>

Convert the notification to an in-app SSE message (per CONTEXT.md D-02).

Source

fn to_sms(&self) -> Option<SmsMessage>

Convert the notification to an SMS message (placeholder per ARCH-FINDING-03; no adapter in this phase).

Source

fn to_push(&self) -> Option<PushMessage>

Convert the notification to a push notification (placeholder per ARCH-FINDING-03; no adapter in this phase).

Source

fn notification_type(&self) -> &'static str

Get the notification type name for logging.

Implementors§