Skip to content

armgit / macro

Public Imported from GitHub
0

Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.

feat(notif): email templating (#1687)

Sean Ayec20acbb12ded
diff --git a/rust/cloud-storage/Cargo.lock b/rust/cloud-storage/Cargo.lock
index aeec9c8b51..53b9f717a6 100644
--- a/rust/cloud-storage/Cargo.lock
+++ b/rust/cloud-storage/Cargo.lock
@@ -326,6 +326,48 @@ dependencies = [
"stable_deref_trait",
]
+[[package]]
+name = "askama"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f75363874b771be265f4ffe307ca705ef6f3baa19011c149da8674a87f1b75c4"
+dependencies = [
+ "askama_derive",
+ "itoa",
+ "percent-encoding",
+ "serde",
+ "serde_json",
+]
+
+[[package]]
+name = "askama_derive"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "129397200fe83088e8a68407a8e2b1f826cf0086b21ccdb866a722c8bcd3a94f"
+dependencies = [
+ "askama_parser",
+ "basic-toml",
+ "memchr",
+ "proc-macro2",
+ "quote",
+ "rustc-hash 2.1.1",
+ "serde",
+ "serde_derive",
+ "syn 2.0.98",
+]
+
+[[package]]
+name = "askama_parser"
+version = "0.14.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d6ab5630b3d5eaf232620167977f95eb51f3432fc76852328774afbd242d4358"
+dependencies = [
+ "memchr",
+ "serde",
+ "serde_derive",
+ "winnow",
+]
+
[[package]]
name = "async-channel"
version = "1.9.0"
@@ -1458,6 +1500,15 @@ version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b"
+[[package]]
+name = "basic-toml"
+version = "0.1.10"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ba62675e8242a4c4e806d12f11d136e626e6c8361d6b829310732241652a178a"
+dependencies = [
+ "serde",
+]
+
[[package]]
name = "bindgen"
version = "0.71.1"
@@ -3315,6 +3366,19 @@ dependencies = [
"tracing",
]
+[[package]]
+name = "email_formatting"
+version = "0.1.0"
+dependencies = [
+ "askama",
+ "chrono",
+ "model_notifications",
+ "notification",
+ "rootcause",
+ "serde",
+ "tracing",
+]
+
[[package]]
name = "email_refresh_handler"
version = "0.1.0"
@@ -6331,10 +6395,12 @@ dependencies = [
"aws-sdk-sns",
"chrono",
"either",
+ "email_formatting",
"inquire",
"macro_aws_config",
"macro_user_id",
"model-entity",
+ "model_notifications",
"models_pagination",
"notification",
"redis",
@@ -10925,6 +10991,15 @@ version = "0.53.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650"
+[[package]]
+name = "winnow"
+version = "0.7.14"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "5a5364e9d77fcdeeaa6062ced926ee3381faa2ee02d3eb83a5c27a8825540829"
+dependencies = [
+ "memchr",
+]
+
[[package]]
name = "wit-bindgen-rt"
version = "0.33.0"
diff --git a/rust/cloud-storage/email_formatting/Cargo.toml b/rust/cloud-storage/email_formatting/Cargo.toml
new file mode 100644
index 0000000000..bcb7b72923
--- /dev/null
+++ b/rust/cloud-storage/email_formatting/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+edition = "2024"
+name = "email_formatting"
+publish = false
+version = "0.1.0"
+
+[dependencies]
+askama = "0.14"
+chrono = { workspace = true }
+model_notifications = { path = "../model_notifications" }
+notification = { path = "../notification" }
+rootcause = { workspace = true }
+serde = { workspace = true, features = ["derive"] }
+tracing = { workspace = true }
diff --git a/rust/cloud-storage/email_formatting/src/lib.rs b/rust/cloud-storage/email_formatting/src/lib.rs
new file mode 100644
index 0000000000..871136e8b5
--- /dev/null
+++ b/rust/cloud-storage/email_formatting/src/lib.rs
@@ -0,0 +1,99 @@
+use std::time::Duration;
+
+use askama::Template;
+use chrono::{DateTime, Utc};
+use model_notifications::NotifEvent;
+use notification::domain::models::{
+ Notification, NotificationExtEmail, RateLimitConfig, RateLimitKey, UserNotificationRow,
+ email_notification_digest::ports::DigestBatch, queue_message::EmailContent,
+};
+use rootcause::Report;
+use serde::{Deserialize, Serialize};
+
+#[derive(Template)]
+#[template(path = "digest.html")]
+struct DigestTemplate {
+ notifs: Vec<NotifPreview>,
+}
+
+struct NotifPreview {
+ created_at: DateTime<Utc>,
+ message: String,
+}
+
+impl NotifPreview {
+ fn new(v: UserNotificationRow<NotifEvent>) -> Option<Self> {
+ Some(NotifPreview {
+ created_at: v.created_at.unwrap_or(Utc::now()),
+ message: format!(
+ "PLACEHOLDER: you received a notification with typename {}",
+ v.notification_event_type
+ ),
+ })
+ }
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize)]
+pub struct EmailDigestNotification {
+ /// the templated html string of the email
+ inner_html_string: String,
+ /// the subject line of the notification
+ subject: String,
+}
+
+impl EmailDigestNotification {
+ pub fn new_from_digest_batch(digest: DigestBatch) -> Result<Self, Report> {
+ let DigestBatch {
+ user_id: _,
+ notifications,
+ ..
+ } = digest;
+
+ fn log_err<E: std::fmt::Debug>(e: &E) {
+ tracing::warn!("{e:?}");
+ }
+
+ let notifs: Vec<_> = notifications
+ .into_iter()
+ .map(|v| v.deserialize_metadata::<NotifEvent>())
+ .filter_map(|res| res.inspect_err(log_err).ok())
+ .filter_map(NotifPreview::new)
+ .collect();
+
+ let templated_len = notifs.len();
+
+ let template = DigestTemplate { notifs };
+
+ let inner_html_string = template.render()?;
+
+ Ok(EmailDigestNotification {
+ inner_html_string,
+ subject: format!("You have {} new notifications on Macro", templated_len),
+ })
+ }
+}
+
+impl Notification for EmailDigestNotification {
+ const TYPE_NAME: &'static str = "email-digest-notification";
+}
+
+impl NotificationExtEmail for EmailDigestNotification {
+ fn format_email(&self) -> EmailContent {
+ EmailContent {
+ subject: self.subject.clone(),
+ body: self.inner_html_string.clone(),
+ }
+ }
+
+ fn rate_limit_config() -> RateLimitConfig {
+ RateLimitConfig {
+ max_count: 60,
+ window: Duration::from_hours(1),
+ }
+ }
+
+ fn rate_limit_key(&self) -> RateLimitKey {
+ // NB: this key is currently intentionally shared across all users out of an abundance of caution to limit over-sending on SES
+ RateLimitKey::from_str_hashed(Self::TYPE_NAME)
+ }
+}
diff --git a/rust/cloud-storage/email_formatting/templates/digest.html b/rust/cloud-storage/email_formatting/templates/digest.html
new file mode 100644
index 0000000000..49e17ec0d4
--- /dev/null
+++ b/rust/cloud-storage/email_formatting/templates/digest.html
@@ -0,0 +1,152 @@
+<div
+ style="
+ padding: 60px 20px;
+ width: 100%;
+ "
+>
+ <div
+ style="
+ font-family: 'Berkeley Mono', 'Courier New', Courier, monospace;
+ background-color: #111;
+ border: 1px solid #444;
+ box-sizing: border-box;
+ border-radius: 4px;
+ max-width: 570px;
+ font-size: 15px;
+ margin: 0 auto;
+ color: #999;
+ width: 100%;
+ "
+ >
+ <div
+ style="
+ background-color: #222;
+ box-sizing: border-box;
+ line-height: 60px;
+ font-size: 17px;
+ padding: 0 20px;
+ height: 60px;
+ width: 100%;
+ "
+ >
+ <div
+ style="
+ border: 1px solid #444;
+ vertical-align: middle;
+ box-sizing: border-box;
+ display: inline-block;
+ border-radius: 20px;
+ margin-right: 10px;
+ height: 40px;
+ width: 40px;
+ "
+ >
+ <!--<SvgNotification/>-->
+ </div>
+ You have {{ notifs.len() }} unread messages
+ </div>
+ <hr
+ style="
+ border-top: 1px dashed #444;
+ border-bottom: none;
+ border-right: none;
+ border-left: none;
+ margin: 0;
+ "
+ />
+ <div
+ style="
+ box-sizing: border-box;
+ padding: 0 20px;
+ "
+ >
+ {% for notif in notifs %}
+ <a
+ style="
+ text-decoration: none;
+ padding: 10px 17px;
+ color: #999;
+ display: block;
+ "
+ href="https://macro.com"
+ target="_blank"
+ >
+ <div
+ style="
+ background-color: #f038;
+ border: 1px solid #f03;
+ box-sizing: border-box;
+ display: inline-block;
+ border-radius: 100%;
+ margin-right: 10px;
+ height: 8px;
+ width: 8px;
+ "
+ >
+ </div>
+ {{ notif.created_at.format("%Y-%m-%d %H:%M:%S") }} {{ notif.message }}
+ </a>
+ {% if !loop.last %}
+ <hr
+ style="
+ border-top: 1px dashed #333;
+ border-bottom: none;
+ border-right: none;
+ border-left: none;
+ margin: 0;
+ "
+ />
+ {% endif %}
+ {% endfor %}
+
+ <hr
+ style="
+ border-top: 1px dashed #333;
+ border-bottom: none;
+ border-right: none;
+ border-left: none;
+ margin: 0;
+ "
+ />
+
+ <table style="width: 100%; cellpadding: 0; border: none;">
+ <tbody>
+ <tr>
+ <td
+ style="
+ vertical-align: middle;
+ padding: 0;
+ width: 50%;
+ "
+ >
+ <a
+ style="
+ background-color: #f04;
+ text-decoration: none;
+ display: inline-block;
+ white-space: nowrap;
+ width: min-content;
+ padding: 2px 10px;
+ color: #111;
+ "
+ href="https://macro.com"
+ target="_blank"
+ >
+ View in Macro
+ </a>
+ </td>
+ <td
+ style="
+ text-align: right;
+ padding: 0;
+ width: 50%;
+ "
+ >
+ <!--<SvgLogo/>-->
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+</div>
diff --git a/rust/cloud-storage/email_formatting/templates/invite.html b/rust/cloud-storage/email_formatting/templates/invite.html
new file mode 100644
index 0000000000..c28e137bcb
--- /dev/null
+++ b/rust/cloud-storage/email_formatting/templates/invite.html
@@ -0,0 +1,199 @@
+<!doctype html>
+<html
+ xmlns:o="urn:schemas-microsoft-com:office:office"
+ xmlns:v="urn:schemas-microsoft-com:vml"
+ xmlns="http://www.w3.org/1999/xhtml"
+>
+ <head>
+ <title>You're Invited to Macro</title>
+ <!--[if !mso]><!-->
+ <meta
+ http-equiv="X-UA-Compatible"
+ content="IE=edge"
+ >
+ <!--<![endif]-->
+ <meta
+ content="text/html; charset=UTF-8"
+ http-equiv="Content-Type"
+ >
+ <meta
+ content="width=device-width, initial-scale=1"
+ name="viewport"
+ >
+ <!--[if mso]>
+ <noscript>
+ <xml>
+ <o:OfficeDocumentSettings>
+ <o:AllowPNG/>
+ <o:PixelsPerInch>96</o:PixelsPerInch>
+ </o:OfficeDocumentSettings>
+ </xml>
+ </noscript>
+ <![endif]-->
+ <!--[if lte mso 11]>
+ <style type="text/css">
+ .mj-outlook-group-fix { width:100% !important; }
+ </style>
+ <![endif]-->
+ <style type="text/css">
+ @font-face {
+ font-family: 'Berkeley Mono';
+ src: url('https://pub-4030931feb3e4212b2ac93166a411ea7.r2.dev/berkley.woff2') format('woff2');
+ font-display: fallback;
+ }
+
+ #outlook a{
+ padding: 0;
+ }
+
+ img{
+ -ms-interpolation-mode: bicubic;
+ text-decoration: none;
+ line-height: 100%;
+ outline: none;
+ height: auto;
+ border:0;
+ }
+
+ .berkeley-font {
+ font-family: 'Berkeley Mono', 'Courier New', Courier, monospace !important;
+ }
+ </style>
+ </head>
+ <body
+ style="
+ -webkit-text-size-adjust: 100%;
+ -ms-text-size-adjust: 100%;
+ word-spacing: normal;
+ padding: 0;
+ margin: 0;
+ "
+ >
+ <div
+ class="berkeley-font"
+ style="
+ box-sizing: border-box;
+ padding: 60px 20px;
+ width: 100%;
+ "
+ >
+ <div
+ class="berkeley-font"
+ style="
+ font-family: 'Berkeley Mono', 'Courier New', Courier, monospace;
+ background-color: #111;
+ border: 1px solid #444;
+ box-sizing: border-box;
+ border-radius: 4px;
+ max-width: 570px;
+ font-size: 15px;
+ margin: 0 auto;
+ overflow: clip;
+ color: #999;
+ width: 100%;
+ "
+ >
+ <div
+ class="berkeley-font"
+ style="
+ font-family: 'Berkeley Mono', 'Courier New', Courier, monospace;
+ background-color: #222;
+ box-sizing: border-box;
+ line-height: 60px;
+ font-size: 17px;
+ padding: 0 20px;
+ height: 60px;
+ width: 100%;
+ "
+ >
+ <div
+ style="
+ border: 1px solid #444;
+ vertical-align: middle;
+ box-sizing: border-box;
+ display: inline-block;
+ border-radius: 20px;
+ margin-right: 3px;
+ overflow: clip;
+ height: 40px;
+ width: 40px;
+ "
+ >
+ <!--user-profile-icon-->
+ </div>
+ User has invited you to Macro
+ </div>
+ <hr
+ style="
+ border: none;
+ border-top: 1px dashed #444;
+ margin: 0;
+ "
+ />
+ <div
+ class="berkeley-font"
+ style="
+ font-family: 'Berkeley Mono', 'Courier New', Courier, monospace;
+ box-sizing: border-box;
+ padding: 20px;
+ "
+ >
+ <div>
+ User has invited you to join them on Macro. Collaborate on documents. Stay in sync with tasks. Search over everything. AI Assistance with anything.
+ </div>
+
+ <table
+ style="
+ mso-table-lspace: 0pt;
+ mso-table-rspace: 0pt;
+ border: none;
+ width: 100%;
+ "
+ cellpadding="0"
+ cellspacing="0"
+ >
+ <tbody>
+ <tr>
+ <td
+ style="
+ vertical-align: bottom;
+ padding: 20px 0 0 0;
+ width: 50%;
+ "
+ >
+ <a
+ class="berkeley-font"
+ style="
+ font-family: 'Berkeley Mono', 'Courier New', Courier, monospace;
+ background-color: #f04;
+ text-decoration: none;
+ display: inline-block;
+ white-space: nowrap;
+ width: min-content;
+ padding: 2px 10px;
+ color: #111;
+ "
+ href="https://macro.com"
+ target="_blank"
+ >
+ Join User
+ </a>
+ </td>
+ <td
+ style="
+ vertical-align: top;
+ text-align: right;
+ padding: 0;
+ width: 50%;
+ "
+ >
+ <!--macro-logo-anim-->
+ </td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+ </body>
+</html>
diff --git a/rust/cloud-storage/notification/src/domain/models.rs b/rust/cloud-storage/notification/src/domain/models.rs
index 6c2cac4d69..f289d71b4a 100644
--- a/rust/cloud-storage/notification/src/domain/models.rs
+++ b/rust/cloud-storage/notification/src/domain/models.rs
@@ -72,7 +72,7 @@ pub struct UserNotificationRow<T> {
}
impl<T> UserNotificationRow<T> {
- /// map the inner T to some U
+ /// Map the inner T to some U.
pub fn map<F, U>(self, f: F) -> UserNotificationRow<U>
where
F: FnOnce(T) -> U,
@@ -107,6 +107,42 @@ impl<T> UserNotificationRow<T> {
sender_id,
}
}
+
+ /// Map the inner T to some U, with a fallible mapping function.
+ pub fn try_map<F, U, E>(self, f: F) -> Result<UserNotificationRow<U>, E>
+ where
+ F: FnOnce(T) -> Result<U, E>,
+ {
+ let UserNotificationRow {
+ owner_id,
+ notification_id,
+ notification_event_type,
+ entity,
+ sent,
+ done,
+ created_at,
+ viewed_at,
+ updated_at,
+ deleted_at,
+ notification_metadata,
+ sender_id,
+ } = self;
+
+ Ok(UserNotificationRow {
+ owner_id,
+ notification_id,
+ notification_event_type,
+ entity,
+ sent,
+ done,
+ created_at,
+ viewed_at,
+ updated_at,
+ deleted_at,
+ notification_metadata: f(notification_metadata)?,
+ sender_id,
+ })
+ }
}
/// A notification metadata value tagged with the notification event type.
@@ -147,51 +183,24 @@ impl UserNotificationRow<serde_json::Value> {
}
}
-impl<T: Serialize> UserNotificationRow<TaggedContent<T>> {
- /// Serialize the [`TaggedContent`] wrapper back into a single JSON value,
- /// producing `{ "tag": "...", "content": ... }`.
- pub fn into_json(self) -> Result<UserNotificationRow<serde_json::Value>, serde_json::Error> {
- let val = serde_json::to_value(&self.notification_metadata)?;
- Ok(self.map(|_| val))
+impl TaggedContent<serde_json::Value> {
+ /// Deserialize the adjacently-tagged content directly into `T` without
+ /// an intermediate serialization roundtrip.
+ pub fn deserialize<T: DeserializeOwned>(self) -> Result<T, serde_json::Error> {
+ let val = serde_json::json!({
+ "tag": self.tag,
+ "content": self.content,
+ });
+ serde_json::from_value(val)
}
}
-impl UserNotificationRow<serde_json::Value> {
- /// Deserialize the JSON metadata into a concrete type `T`.
- pub fn deserialize_json<T: DeserializeOwned>(
+impl UserNotificationRow<TaggedContent<serde_json::Value>> {
+ /// Deserialize the adjacently-tagged metadata into a concrete type `T`.
+ pub fn deserialize_metadata<T: DeserializeOwned>(
self,
) -> Result<UserNotificationRow<T>, serde_json::Error> {
- let UserNotificationRow {
- owner_id,
- notification_id,
- notification_event_type,
- entity,
- sent,
- done,
- created_at,
- viewed_at,
- updated_at,
- deleted_at,
- notification_metadata,
- sender_id,
- } = self;
-
- let val = serde_json::from_value(notification_metadata)?;
-
- Ok(UserNotificationRow {
- owner_id,
- notification_id,
- notification_event_type,
- entity,
- sent,
- done,
- created_at,
- viewed_at,
- updated_at,
- deleted_at,
- notification_metadata: val,
- sender_id,
- })
+ self.try_map(|tagged| tagged.deserialize())
}
}
diff --git a/rust/cloud-storage/notification_sandbox/Cargo.toml b/rust/cloud-storage/notification_sandbox/Cargo.toml
index 780d71f381..87d933f2d8 100644
--- a/rust/cloud-storage/notification_sandbox/Cargo.toml
+++ b/rust/cloud-storage/notification_sandbox/Cargo.toml
@@ -9,18 +9,29 @@ aws-sdk-sesv2 = { workspace = true }
aws-sdk-sns = { workspace = true }
chrono = { workspace = true }
either = { workspace = true }
+email_formatting = { path = "../email_formatting" }
inquire = { workspace = true }
macro_aws_config = { path = "../macro_aws_config" }
macro_user_id = { path = "../macro_user_id" }
model-entity = { path = "../model-entity" }
+model_notifications = { path = "../model_notifications" }
models_pagination = { path = "../models_pagination" }
notification = { path = "../notification" }
-redis = { workspace = true, features = ["aio", "tokio-comp", "tokio-native-tls-comp"] }
+redis = { workspace = true, features = [
+ "aio",
+ "tokio-comp",
+ "tokio-native-tls-comp",
+] }
rootcause = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sqlx = { workspace = true }
-tokio = { workspace = true, features = ["macros", "rt-multi-thread", "signal", "sync"] }
+tokio = { workspace = true, features = [
+ "macros",
+ "rt-multi-thread",
+ "signal",
+ "sync",
+] }
tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["fmt"] }
uuid = { workspace = true }
diff --git a/rust/cloud-storage/notification_sandbox/src/adapters/interactive_mobile.rs b/rust/cloud-storage/notification_sandbox/src/adapters/interactive_mobile.rs
index 00d37966e8..0a728025e0 100644
--- a/rust/cloud-storage/notification_sandbox/src/adapters/interactive_mobile.rs
+++ b/rust/cloud-storage/notification_sandbox/src/adapters/interactive_mobile.rs
@@ -11,6 +11,8 @@ use tokio::sync::mpsc;
pub struct PushPromptRequest {
/// The endpoint ARN being pushed to.
pub endpoint_arn: String,
+ /// The mock SNS message ID that will be used if the push "succeeds".
+ pub message_id: String,
/// Channel to send back whether the push "succeeded".
pub reply: tokio::sync::oneshot::Sender<bool>,
}
@@ -28,10 +30,12 @@ impl NotificationSender for InteractiveMobileSender {
_notification: &APNSPushNotification<T>,
_attributes: &MessageAttributes,
) -> Result<String, Report> {
+ let msg_id = format!("mock-msg-{}", uuid::Uuid::new_v4());
let (reply_tx, reply_rx) = tokio::sync::oneshot::channel();
self.prompt_tx
.send(PushPromptRequest {
endpoint_arn: endpoint_arn.to_string(),
+ message_id: msg_id.clone(),
reply: reply_tx,
})
.map_err(|_| rootcause::report!("foreground prompt channel closed"))?;
@@ -41,7 +45,6 @@ impl NotificationSender for InteractiveMobileSender {
.map_err(|_| rootcause::report!("foreground prompt reply dropped"))?;
if succeeded {
- let msg_id = format!("mock-msg-{}", uuid::Uuid::new_v4());
Ok(msg_id)
} else {
rootcause::bail!("Simulated push failure for {endpoint_arn}");
diff --git a/rust/cloud-storage/notification_sandbox/src/main.rs b/rust/cloud-storage/notification_sandbox/src/main.rs
index b8dee04e7a..da5d72dde8 100644
--- a/rust/cloud-storage/notification_sandbox/src/main.rs
+++ b/rust/cloud-storage/notification_sandbox/src/main.rs
@@ -6,9 +6,11 @@ use std::collections::{HashMap, HashSet};
use std::sync::{Arc, Mutex};
use std::time::Duration;
+use email_formatting::EmailDigestNotification;
use macro_user_id::cowlike::CowLike;
use macro_user_id::user_id::MacroUserIdStr;
use model_entity::EntityType;
+use model_notifications::ChannelMessageSendMetadata;
use notification::domain::models::email_notification_digest::ports::MessageId;
use notification::domain::models::email_notification_digest::{
EmailBlockList, ExplicitInviteAllowList, NotificationSetBuilder, StateMachineDecisionC,
@@ -280,7 +282,7 @@ fn prompt_push_result(req: PushPromptRequest) {
.unwrap_or(false);
if succeeded {
- println!(" -> SUCCESS");
+ println!(" -> SUCCESS (message_id: {})", req.message_id);
} else {
println!(" -> FAILED");
}
@@ -297,8 +299,14 @@ async fn run_notification_cycle<I: NotificationIngress>(
let request = SendNotificationRequestBuilder {
notification_entity: EntityType::Channel.with_entity_str("sandbox-entity-id"),
- notification: SandboxNotification {
- message: "Sandbox test notification".to_string(),
+ notification: ChannelMessageSendMetadata {
+ sender: MacroUserIdStr::try_from_email("[email protected]").unwrap(),
+ message_content: "This is a message".to_string(),
+ message_id: "message_id".to_string(),
+ common: model_notifications::CommonChannelMetadata {
+ channel_type: model_notifications::ChannelType::Public,
+ channel_name: "test-channel-name".to_string(),
+ },
},
sender_id: None,
recipient_ids: HashSet::from([user_id.copied()]),
@@ -369,11 +377,7 @@ async fn poll_email_digests(egress: &impl NotificationEgress) -> Result<(), Repo
batch: notification::domain::models::email_notification_digest::ports::DigestBatch,
) -> Result<SandboxNotification, Report> {
Ok(SandboxNotification {
- message: format!(
- "You have {} new notification(s) \n\n {:#?}",
- batch.notifications.len(),
- batch
- ),
+ inner: EmailDigestNotification::new_from_digest_batch(batch)?,
})
}
diff --git a/rust/cloud-storage/notification_sandbox/src/sandbox_notification.rs b/rust/cloud-storage/notification_sandbox/src/sandbox_notification.rs
index 956b3bc6b7..7dc598bd05 100644
--- a/rust/cloud-storage/notification_sandbox/src/sandbox_notification.rs
+++ b/rust/cloud-storage/notification_sandbox/src/sandbox_notification.rs
@@ -1,3 +1,4 @@
+use email_formatting::EmailDigestNotification;
use macro_user_id::user_id::MacroUserIdStr;
use notification::domain::models::apple::APNSPushNotification;
use notification::domain::models::mobile::NotifCollapseKey;
@@ -10,7 +11,7 @@ use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SandboxNotification {
/// A test message.
- pub message: String,
+ pub inner: EmailDigestNotification,
}
impl Notification for SandboxNotification {
@@ -39,10 +40,7 @@ impl NotificationExtIos for SandboxNotification {
impl NotificationExtEmail for SandboxNotification {
fn format_email(&self) -> EmailContent {
- EmailContent {
- subject: "Sandbox Notification".to_string(),
- body: self.message.clone(),
- }
+ self.inner.format_email()
}
fn rate_limit_config() -> RateLimitConfig {
diff --git a/rust/cloud-storage/notification_service/src/api/user_notification.rs b/rust/cloud-storage/notification_service/src/api/user_notification.rs
index 214bbc2c63..7c1ef3d644 100644
--- a/rust/cloud-storage/notification_service/src/api/user_notification.rs
+++ b/rust/cloud-storage/notification_service/src/api/user_notification.rs
@@ -90,9 +90,7 @@ pub struct GetAllUserNotificationsResponse {
pub fn to_typed_row(
row: UserNotificationRow<serde_json::Value>,
) -> Result<UserNotificationRow<NotifEvent>, serde_json::Error> {
- row.into_tagged()
- .into_json()?
- .deserialize_json::<NotifEvent>()
+ row.into_tagged().deserialize_metadata()
}
/// Build the strongly typed router.