laravel-template-engine 0.2.0

Templates for emails, documents and notifications that your team edits, stored in the database
Documentation
//! What the template engine dispatches. There's no send log in the package: a listener of
//! these events writes one if the application needs it.

use laravel::event::Event;

use crate::template::Kind;

/// A template was rendered: for an email, a document, a preview or a test send.
#[derive(Debug, Clone, Event)]
pub struct TemplateRendered {
    /// The template's key; `0` for a preview of an unsaved template.
    pub template_id: i64,
    /// The template type.
    pub type_key: String,
    /// Email or document.
    pub kind: Kind,
    /// The language of the text that was used.
    pub locale: String,
}

/// An email made from a template was handed to the mailer.
#[derive(Debug, Clone, Event)]
pub struct TemplateMessageSent {
    /// The template's key.
    pub template_id: i64,
    /// The template type.
    pub type_key: String,
    /// Always [`Kind::Mail`] for now; other channels come later.
    pub kind: Kind,
    /// The language of the text that was used.
    pub locale: String,
    /// The address in `to`.
    pub recipient: String,
}

/// An email made from a template couldn't be rendered or sent. When the mailer failed, the
/// queue tries again and this is dispatched for each failed attempt; a template that doesn't
/// render isn't tried again.
#[derive(Debug, Clone, Event)]
pub struct TemplateMessageFailed {
    /// The template's key.
    pub template_id: i64,
    /// The template type.
    pub type_key: String,
    /// Always [`Kind::Mail`] for now.
    pub kind: Kind,
    /// The language of the text, when it was chosen before the failure.
    pub locale: Option<String>,
    /// The address in `to`.
    pub recipient: String,
    /// What went wrong.
    pub error: String,
}