+
+ );
+}
diff --git a/templates/analytics/server/lib/dashboard-report.ts b/templates/analytics/server/lib/dashboard-report.ts
index ef144d7734..03a58f616b 100644
--- a/templates/analytics/server/lib/dashboard-report.ts
+++ b/templates/analytics/server/lib/dashboard-report.ts
@@ -18,6 +18,7 @@ import {
type DashboardReportCaptureOutcome,
type DashboardReportSubscription,
} from "./dashboard-report-subscriptions";
+import { ANALYTICS_DASHBOARD_REPORT_EMAIL_ID } from "./emails";
const DATE_FILTER_TYPES: ReadonlySet = new Set([
"date",
@@ -326,6 +327,7 @@ export async function sendDashboardReportSubscription(
? { attachments: rendered.attachments }
: {}),
timeoutMs: emailTimeoutMs,
+ templateId: ANALYTICS_DASHBOARD_REPORT_EMAIL_ID,
});
}
diff --git a/templates/analytics/server/lib/emails.ts b/templates/analytics/server/lib/emails.ts
new file mode 100644
index 0000000000..12813dfc84
--- /dev/null
+++ b/templates/analytics/server/lib/emails.ts
@@ -0,0 +1,51 @@
+/**
+ * Catalog entries for the transactional emails Analytics sends.
+ *
+ * Registered from `server/plugins/transactional-emails.ts` so Dispatch can list
+ * and preview them without the app having sent anything yet.
+ */
+
+import { defineTransactionalEmail } from "@agent-native/core/email-catalog";
+import { emailStrong, renderEmail } from "@agent-native/core/server";
+
+export const ANALYTICS_DASHBOARD_REPORT_EMAIL_ID = "analytics.dashboard-report";
+
+let registered = false;
+
+export function registerAnalyticsEmails(): void {
+ if (registered) return;
+ registered = true;
+
+ defineTransactionalEmail({
+ id: ANALYTICS_DASHBOARD_REPORT_EMAIL_ID,
+ name: "Scheduled dashboard report",
+ trigger:
+ "A dashboard report subscription comes due and at least one panel produced usable data. A run where every queried panel failed throws instead of mailing, and a degraded run is skipped when the subscription asks for complete reports only.",
+ recipientLabel: "Subscription recipients",
+ recipient:
+ "The normalized recipient list stored on the subscription. One email per address, all carrying the same rendered snapshot.",
+ senderLabel: "Default sender",
+ sender:
+ "The configured default sender. This call site sets no `from`, `fromName`, `replyTo`, or `appSender`.",
+ // The real renderer runs every panel query and rasterizes charts, so it
+ // cannot back a preview that must stay offline. This shows the frame a
+ // recipient sees; the panel body is whatever that run produced.
+ preview: () => ({
+ subject: "Daily dashboard: Growth overview — 3/4/2025",
+ ...renderEmail({
+ preheader: "Your daily Growth overview report is ready.",
+ heading: "Daily dashboard: Growth overview",
+ paragraphs: [
+ `This report renders each panel of ${emailStrong("Growth overview")} as of the run time, with charts drawn server-side and attached inline.`,
+ "Panels that could not be queried are called out in place rather than dropped, so a partial report never reads as a complete one.",
+ ],
+ cta: {
+ label: "Open dashboard",
+ url: "https://example.com/dashboards/dash_sample",
+ },
+ footer:
+ "You received this because you are on the recipient list for this dashboard report.",
+ }),
+ }),
+ });
+}
diff --git a/templates/analytics/server/plugins/transactional-emails.ts b/templates/analytics/server/plugins/transactional-emails.ts
new file mode 100644
index 0000000000..e689d4c56e
--- /dev/null
+++ b/templates/analytics/server/plugins/transactional-emails.ts
@@ -0,0 +1,5 @@
+import { registerAnalyticsEmails } from "../lib/emails";
+
+export default function registerTransactionalEmails(): void {
+ registerAnalyticsEmails();
+}
diff --git a/templates/calendar/server/lib/booking-emails.ts b/templates/calendar/server/lib/booking-emails.ts
index 7c81d1ee6f..38ff844412 100644
--- a/templates/calendar/server/lib/booking-emails.ts
+++ b/templates/calendar/server/lib/booking-emails.ts
@@ -11,6 +11,12 @@ import {
DEFAULT_BOOKING_TIMEZONE,
safeBookingTimeZone,
} from "./booking-timezone.js";
+import {
+ CALENDAR_BOOKING_CANCELLED_EMAIL_ID,
+ CALENDAR_BOOKING_CANCELLED_HOST_EMAIL_ID,
+ CALENDAR_BOOKING_CONFIRMED_EMAIL_ID,
+ CALENDAR_BOOKING_RECEIVED_EMAIL_ID,
+} from "./emails.js";
function stripCrlf(value: string | undefined): string {
return (value ?? "").replace(/[\r\n]+/g, " ").trim();
@@ -57,6 +63,128 @@ async function sendBestEffort(
}
}
+export function renderBookingConfirmedEmail({
+ title,
+ when,
+ host,
+ manageUrl,
+ meetingLink,
+}: {
+ title: string;
+ when: string;
+ host: string;
+ manageUrl: string;
+ meetingLink?: string | null;
+}) {
+ const paragraphs = [
+ `You're booked for ${emailStrong(title)} with ${emailStrong(host)}.`,
+ `Time: ${emailStrong(when)}.`,
+ ];
+ if (meetingLink) {
+ paragraphs.push(`Meeting link: ${emailLink("Join meeting", meetingLink)}.`);
+ }
+
+ return {
+ subject: `Confirmed: ${title}`,
+ ...renderEmail({
+ preheader: `You're booked for ${title} on ${when}.`,
+ heading: "Your meeting is booked",
+ paragraphs,
+ cta: { label: "Manage booking", url: manageUrl },
+ footer:
+ "Use the manage link if you need to cancel or reschedule this meeting.",
+ }),
+ };
+}
+
+export function renderBookingReceivedEmail({
+ title,
+ when,
+ attendeeName,
+ attendee,
+ manageUrl,
+ meetingLink,
+}: {
+ title: string;
+ when: string;
+ attendeeName: string;
+ attendee: string;
+ manageUrl: string;
+ meetingLink?: string | null;
+}) {
+ return {
+ subject: `New booking: ${title}`,
+ ...renderEmail({
+ preheader: `${attendeeName} booked ${title} on ${when}.`,
+ heading: "New booking",
+ paragraphs: [
+ `${emailStrong(attendeeName)} booked ${emailStrong(title)}.`,
+ `Time: ${emailStrong(when)}.`,
+ `Guest: ${emailStrong(attendee)}.`,
+ ...(meetingLink
+ ? [`Meeting link: ${emailLink("Join meeting", meetingLink)}.`]
+ : []),
+ ],
+ cta: { label: "View booking", url: manageUrl },
+ footer: "This booking was created from your calendar booking link.",
+ }),
+ };
+}
+
+export function renderBookingCancelledEmail({
+ title,
+ when,
+ host,
+ bookAgainUrl,
+}: {
+ title: string;
+ when: string;
+ host: string;
+ bookAgainUrl?: string;
+}) {
+ return {
+ subject: `Cancelled: ${title}`,
+ ...renderEmail({
+ preheader: `${title} on ${when} was cancelled.`,
+ heading: "Your meeting was cancelled",
+ paragraphs: [
+ `${emailStrong(title)} with ${emailStrong(host || "the host")} has been cancelled.`,
+ `Original time: ${emailStrong(when)}.`,
+ ],
+ cta: bookAgainUrl
+ ? { label: "Book another time", url: bookAgainUrl }
+ : undefined,
+ footer: "If this was unexpected, contact the meeting host.",
+ }),
+ };
+}
+
+export function renderBookingCancelledHostEmail({
+ title,
+ when,
+ attendeeName,
+ attendee,
+}: {
+ title: string;
+ when: string;
+ attendeeName: string;
+ attendee: string;
+}) {
+ return {
+ subject: `Cancelled booking: ${title}`,
+ ...renderEmail({
+ preheader: `${attendeeName}'s booking for ${title} was cancelled.`,
+ heading: "Booking cancelled",
+ paragraphs: [
+ `${emailStrong(attendeeName)}'s booking for ${emailStrong(title)} was cancelled.`,
+ `Original time: ${emailStrong(when)}.`,
+ `Guest: ${emailStrong(attendee)}.`,
+ ],
+ footer: "No further action is needed.",
+ }),
+ };
+}
+
export async function sendBookingConfirmationEmails({
booking,
hostEmail,
@@ -74,54 +202,31 @@ export async function sendBookingConfirmationEmails({
const attendee = stripCrlf(booking.email);
const attendeeName = stripCrlf(booking.name) || "there";
- const attendeeParagraphs = [
- `You're booked for ${emailStrong(title)} with ${emailStrong(host)}.`,
- `Time: ${emailStrong(when)}.`,
- ];
- if (booking.meetingLink) {
- attendeeParagraphs.push(
- `Meeting link: ${emailLink("Join meeting", booking.meetingLink)}.`,
- );
- }
-
- const attendeeEmail = renderEmail({
- preheader: `You're booked for ${title} on ${when}.`,
- heading: "Your meeting is booked",
- paragraphs: attendeeParagraphs,
- cta: { label: "Manage booking", url: manageUrl },
- footer:
- "Use the manage link if you need to cancel or reschedule this meeting.",
- });
-
await sendBestEffort("attendee confirmation", {
to: attendee,
- subject: `Confirmed: ${title}`,
- html: attendeeEmail.html,
- text: attendeeEmail.text,
+ ...renderBookingConfirmedEmail({
+ title,
+ when,
+ host,
+ manageUrl,
+ meetingLink: booking.meetingLink,
+ }),
replyTo: host,
- });
-
- const hostEmailMessage = renderEmail({
- preheader: `${attendeeName} booked ${title} on ${when}.`,
- heading: "New booking",
- paragraphs: [
- `${emailStrong(attendeeName)} booked ${emailStrong(title)}.`,
- `Time: ${emailStrong(when)}.`,
- `Guest: ${emailStrong(attendee)}.`,
- ...(booking.meetingLink
- ? [`Meeting link: ${emailLink("Join meeting", booking.meetingLink)}.`]
- : []),
- ],
- cta: { label: "View booking", url: manageUrl },
- footer: "This booking was created from your calendar booking link.",
+ templateId: CALENDAR_BOOKING_CONFIRMED_EMAIL_ID,
});
await sendBestEffort("host notification", {
to: host,
- subject: `New booking: ${title}`,
- html: hostEmailMessage.html,
- text: hostEmailMessage.text,
+ ...renderBookingReceivedEmail({
+ title,
+ when,
+ attendeeName,
+ attendee,
+ manageUrl,
+ meetingLink: booking.meetingLink,
+ }),
replyTo: attendee,
+ templateId: CALENDAR_BOOKING_RECEIVED_EMAIL_ID,
});
}
@@ -142,45 +247,24 @@ export async function sendBookingCancellationEmails({
const attendee = stripCrlf(booking.email);
const attendeeName = stripCrlf(booking.name) || "The guest";
- const attendeeEmail = renderEmail({
- preheader: `${title} on ${when} was cancelled.`,
- heading: "Your meeting was cancelled",
- paragraphs: [
- `${emailStrong(title)} with ${emailStrong(host || "the host")} has been cancelled.`,
- `Original time: ${emailStrong(when)}.`,
- ],
- cta: bookAgainUrl
- ? { label: "Book another time", url: bookAgainUrl }
- : undefined,
- footer: "If this was unexpected, contact the meeting host.",
- });
-
await sendBestEffort("attendee cancellation", {
to: attendee,
- subject: `Cancelled: ${title}`,
- html: attendeeEmail.html,
- text: attendeeEmail.text,
+ ...renderBookingCancelledEmail({ title, when, host, bookAgainUrl }),
replyTo: host || undefined,
+ templateId: CALENDAR_BOOKING_CANCELLED_EMAIL_ID,
});
if (!host) return;
- const hostEmailMessage = renderEmail({
- preheader: `${attendeeName}'s booking for ${title} was cancelled.`,
- heading: "Booking cancelled",
- paragraphs: [
- `${emailStrong(attendeeName)}'s booking for ${emailStrong(title)} was cancelled.`,
- `Original time: ${emailStrong(when)}.`,
- `Guest: ${emailStrong(attendee)}.`,
- ],
- footer: "No further action is needed.",
- });
-
await sendBestEffort("host cancellation notification", {
to: host,
- subject: `Cancelled booking: ${title}`,
- html: hostEmailMessage.html,
- text: hostEmailMessage.text,
+ ...renderBookingCancelledHostEmail({
+ title,
+ when,
+ attendeeName,
+ attendee,
+ }),
replyTo: attendee,
+ templateId: CALENDAR_BOOKING_CANCELLED_HOST_EMAIL_ID,
});
}
diff --git a/templates/calendar/server/lib/emails.ts b/templates/calendar/server/lib/emails.ts
new file mode 100644
index 0000000000..06d2731a56
--- /dev/null
+++ b/templates/calendar/server/lib/emails.ts
@@ -0,0 +1,167 @@
+/**
+ * Catalog entries for the transactional emails Calendar sends.
+ *
+ * Registered from `server/plugins/transactional-emails.ts` so Dispatch can list
+ * and preview them without the app having sent anything yet.
+ */
+
+import { defineTransactionalEmail } from "@agent-native/core/email-catalog";
+
+import {
+ renderBookingCancelledEmail,
+ renderBookingCancelledHostEmail,
+ renderBookingConfirmedEmail,
+ renderBookingReceivedEmail,
+} from "./booking-emails.js";
+import { renderEventGuestNote } from "./event-guest-notifications.js";
+
+/** Obviously-fake sample data — these render in a preview pane, never send. */
+const SAMPLE_TITLE = "Intro call";
+const SAMPLE_WHEN = "Tuesday, March 4, 2025, 10:00 AM - 10:30 AM PST";
+const SAMPLE_HOST = "dana.hill@example.com";
+const SAMPLE_GUEST = "sam.rivera@example.com";
+const SAMPLE_GUEST_NAME = "Sam Rivera";
+const SAMPLE_MANAGE_URL = "https://example.com/book/dana/manage/sample-token";
+const SAMPLE_BOOK_AGAIN_URL = "https://example.com/book/dana/intro-call";
+const SAMPLE_MEETING_LINK = "https://meet.example.com/sample-intro-call";
+
+export const CALENDAR_BOOKING_CONFIRMED_EMAIL_ID = "calendar.booking-confirmed";
+export const CALENDAR_BOOKING_RECEIVED_EMAIL_ID = "calendar.booking-received";
+export const CALENDAR_BOOKING_CANCELLED_EMAIL_ID = "calendar.booking-cancelled";
+export const CALENDAR_BOOKING_CANCELLED_HOST_EMAIL_ID =
+ "calendar.booking-cancelled-host";
+export const CALENDAR_EVENT_UPDATE_NOTE_EMAIL_ID = "calendar.event-update-note";
+export const CALENDAR_EVENT_CANCELLATION_NOTE_EMAIL_ID =
+ "calendar.event-cancellation-note";
+
+let registered = false;
+
+export function registerCalendarEmails(): void {
+ if (registered) return;
+ registered = true;
+
+ defineTransactionalEmail({
+ id: CALENDAR_BOOKING_CONFIRMED_EMAIL_ID,
+ name: "Booking confirmed (guest)",
+ trigger:
+ "A guest completes a booking on a public `/book/{username}/{slug}` page and the booking row is created.",
+ recipientLabel: "Booking guest",
+ recipient:
+ "The email address the guest typed into the booking form (`booking.email`).",
+ senderLabel: "Default, reply-to host",
+ sender:
+ "The configured EMAIL_FROM, with reply-to set to the booking link owner's address.",
+ preview: () =>
+ renderBookingConfirmedEmail({
+ title: SAMPLE_TITLE,
+ when: SAMPLE_WHEN,
+ host: SAMPLE_HOST,
+ manageUrl: SAMPLE_MANAGE_URL,
+ meetingLink: SAMPLE_MEETING_LINK,
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CALENDAR_BOOKING_RECEIVED_EMAIL_ID,
+ name: "New booking (host)",
+ trigger:
+ "Sent alongside the guest confirmation, immediately after a public booking is created.",
+ recipientLabel: "Booking link owner",
+ recipient:
+ "The owner of the booking link, looked up from the link's slug at send time.",
+ senderLabel: "Default, reply-to guest",
+ sender:
+ "The configured EMAIL_FROM, with reply-to set to the guest so the host can reply directly.",
+ preview: () =>
+ renderBookingReceivedEmail({
+ title: SAMPLE_TITLE,
+ when: SAMPLE_WHEN,
+ attendeeName: SAMPLE_GUEST_NAME,
+ attendee: SAMPLE_GUEST,
+ manageUrl: SAMPLE_MANAGE_URL,
+ meetingLink: SAMPLE_MEETING_LINK,
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CALENDAR_BOOKING_CANCELLED_EMAIL_ID,
+ name: "Booking cancelled (guest)",
+ trigger:
+ "A booking that was not already cancelled is cancelled, either by the guest through the manage/cancel token link or by someone with access to the booking link.",
+ recipientLabel: "Booking guest",
+ recipient: "The guest address stored on the booking row.",
+ senderLabel: "Default, reply-to host",
+ sender:
+ "The configured EMAIL_FROM, with reply-to set to the host when a host address could be resolved from the link slug.",
+ preview: () =>
+ renderBookingCancelledEmail({
+ title: SAMPLE_TITLE,
+ when: SAMPLE_WHEN,
+ host: SAMPLE_HOST,
+ bookAgainUrl: SAMPLE_BOOK_AGAIN_URL,
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CALENDAR_BOOKING_CANCELLED_HOST_EMAIL_ID,
+ name: "Booking cancelled (host)",
+ trigger:
+ "Sent after the guest cancellation notice, and only when a host address could be resolved from the booking link slug.",
+ recipientLabel: "Booking link owner",
+ recipient: "The booking link owner's address.",
+ senderLabel: "Default, reply-to guest",
+ sender:
+ "The configured EMAIL_FROM, with reply-to set to the guest who was booked.",
+ preview: () =>
+ renderBookingCancelledHostEmail({
+ title: SAMPLE_TITLE,
+ when: SAMPLE_WHEN,
+ attendeeName: SAMPLE_GUEST_NAME,
+ attendee: SAMPLE_GUEST,
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CALENDAR_EVENT_UPDATE_NOTE_EMAIL_ID,
+ name: "Event update note",
+ trigger:
+ "`update-event` runs with a non-empty guest notification message. Google Calendar still sends its own update invite; this carries only the organizer's note.",
+ recipientLabel: "Event attendees",
+ recipient:
+ "Every attendee on the event with a syntactically valid address, excluding the organizer's own `self` attendee row. One email per address.",
+ senderLabel: "Default, reply-to organizer",
+ sender:
+ "The configured EMAIL_FROM, with reply-to set to the organizer running the update.",
+ preview: () =>
+ renderEventGuestNote({
+ title: "Design review",
+ organizer: "Dana Hill",
+ message: "Moving this an hour later so the whole team can join.",
+ when: SAMPLE_WHEN,
+ kind: "update",
+ htmlLink: "https://calendar.example.com/event/sample",
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CALENDAR_EVENT_CANCELLATION_NOTE_EMAIL_ID,
+ name: "Event cancellation note",
+ trigger:
+ "`delete-event` runs with guest notification requested and a non-empty message. Google Calendar sends the cancellation itself; this carries only the organizer's note.",
+ recipientLabel: "Event attendees",
+ recipient:
+ "Every attendee on the deleted event with a syntactically valid address, excluding the organizer's own `self` attendee row. One email per address.",
+ senderLabel: "Default, reply-to organizer",
+ sender:
+ "The configured EMAIL_FROM, with reply-to set to the organizer running the deletion.",
+ preview: () =>
+ renderEventGuestNote({
+ title: "Design review",
+ organizer: "Dana Hill",
+ message: "Cancelling this week — we will pick it up after the launch.",
+ when: SAMPLE_WHEN,
+ kind: "cancellation",
+ appliesTo: "all events in the series",
+ }),
+ });
+}
diff --git a/templates/calendar/server/lib/event-guest-notifications.ts b/templates/calendar/server/lib/event-guest-notifications.ts
index 56bfda4277..2bd72d83e1 100644
--- a/templates/calendar/server/lib/event-guest-notifications.ts
+++ b/templates/calendar/server/lib/event-guest-notifications.ts
@@ -6,6 +6,10 @@ import {
} from "@agent-native/core/server";
import type { CalendarEvent, DeleteEventScope } from "../../shared/api.js";
+import {
+ CALENDAR_EVENT_CANCELLATION_NOTE_EMAIL_ID,
+ CALENDAR_EVENT_UPDATE_NOTE_EMAIL_ID,
+} from "./emails.js";
export interface GuestNotificationResult {
requested: boolean;
@@ -96,6 +100,53 @@ function scopeLabel(scope: DeleteEventScope | undefined): string | undefined {
return "this and following events";
}
+export function renderEventGuestNote({
+ title,
+ organizer,
+ message,
+ when,
+ kind,
+ appliesTo,
+ htmlLink,
+}: {
+ title: string;
+ organizer: string;
+ message: string;
+ when: string;
+ kind: GuestNotificationKind;
+ appliesTo?: string;
+ htmlLink?: string | null;
+}) {
+ const heading =
+ kind === "cancellation" ? "Event cancellation note" : "Event update note";
+ const subjectPrefix =
+ kind === "cancellation" ? "Cancellation note" : "Update note";
+ const eventAction = kind === "cancellation" ? "cancelling" : "updating";
+ const paragraphs = [
+ `${emailStrong(organizer)} added this note while ${eventAction} ${emailStrong(title)}.`,
+ messageParagraph(message),
+ `When: ${emailStrong(when)}.`,
+ ];
+ if (appliesTo) {
+ paragraphs.push(`Applies to: ${emailStrong(appliesTo)}.`);
+ }
+
+ return {
+ subject: `${subjectPrefix}: ${title}`,
+ ...renderEmail({
+ preheader: `${subjectPrefix}: ${title}`,
+ heading,
+ paragraphs,
+ cta:
+ kind === "update" && htmlLink
+ ? { label: "Open in Google Calendar", url: htmlLink }
+ : undefined,
+ footer:
+ "Google Calendar sends the calendar update separately. This message carries the organizer note.",
+ }),
+ };
+}
+
export async function sendEventGuestNotificationNote({
event,
organizerEmail,
@@ -138,33 +189,14 @@ export async function sendEventGuestNotificationNote({
};
}
- const title = stripCrlf(event.title) || "Calendar event";
- const organizer = stripCrlf(event.organizer?.displayName) || organizerEmail;
- const heading =
- kind === "cancellation" ? "Event cancellation note" : "Event update note";
- const subjectPrefix =
- kind === "cancellation" ? "Cancellation note" : "Update note";
- const eventAction = kind === "cancellation" ? "cancelling" : "updating";
- const paragraphs = [
- `${emailStrong(organizer)} added this note while ${eventAction} ${emailStrong(title)}.`,
- messageParagraph(normalizedMessage),
- `When: ${emailStrong(formatWhen(event))}.`,
- ];
- const appliesTo = scopeLabel(scope);
- if (appliesTo) {
- paragraphs.push(`Applies to: ${emailStrong(appliesTo)}.`);
- }
-
- const rendered = renderEmail({
- preheader: `${subjectPrefix}: ${title}`,
- heading,
- paragraphs,
- cta:
- kind === "update" && event.htmlLink
- ? { label: "Open in Google Calendar", url: event.htmlLink }
- : undefined,
- footer:
- "Google Calendar sends the calendar update separately. This message carries the organizer note.",
+ const rendered = renderEventGuestNote({
+ title: stripCrlf(event.title) || "Calendar event",
+ organizer: stripCrlf(event.organizer?.displayName) || organizerEmail,
+ message: normalizedMessage,
+ when: formatWhen(event),
+ kind,
+ appliesTo: scopeLabel(scope),
+ htmlLink: event.htmlLink,
});
let sentCount = 0;
@@ -174,10 +206,14 @@ export async function sendEventGuestNotificationNote({
try {
await sendEmail({
to,
- subject: `${subjectPrefix}: ${title}`,
+ subject: rendered.subject,
html: rendered.html,
text: rendered.text,
replyTo: organizerEmail,
+ templateId:
+ kind === "cancellation"
+ ? CALENDAR_EVENT_CANCELLATION_NOTE_EMAIL_ID
+ : CALENDAR_EVENT_UPDATE_NOTE_EMAIL_ID,
});
sentCount += 1;
} catch (error) {
diff --git a/templates/calendar/server/plugins/transactional-emails.ts b/templates/calendar/server/plugins/transactional-emails.ts
new file mode 100644
index 0000000000..3c0763fd29
--- /dev/null
+++ b/templates/calendar/server/plugins/transactional-emails.ts
@@ -0,0 +1,5 @@
+import { registerCalendarEmails } from "../lib/emails.js";
+
+export default function registerTransactionalEmails(): void {
+ registerCalendarEmails();
+}
diff --git a/templates/clips/actions/invite-member.ts b/templates/clips/actions/invite-member.ts
index 98a31af403..b97f0a3ed8 100644
--- a/templates/clips/actions/invite-member.ts
+++ b/templates/clips/actions/invite-member.ts
@@ -24,6 +24,7 @@ import { and, eq, sql } from "drizzle-orm";
import { z } from "zod";
import { getDb } from "../server/db/index.js";
+import { CLIPS_ORGANIZATION_INVITE_EMAIL_ID } from "../server/lib/emails.js";
import {
getCurrentOwnerEmail,
nanoid,
@@ -67,6 +68,36 @@ async function fetchOrgName(orgId: string): Promise {
return row?.name ?? "Organization";
}
+export function renderClipsInviteEmail({
+ appName,
+ orgName,
+ inviter,
+ role,
+ inviteUrl,
+}: {
+ appName: string;
+ orgName: string;
+ inviter: string;
+ role: "admin" | "member";
+ inviteUrl: string;
+}) {
+ return {
+ subject: `You're invited to ${orgName} on ${appName}`,
+ ...renderEmail({
+ brandName: appName,
+ preheader: `${inviter} invited you to ${orgName} on ${appName}.`,
+ heading: `You're invited to join ${orgName}`,
+ paragraphs: [
+ `${emailStrong(inviter)} invited you to the ${emailStrong(orgName)} organization on ${emailStrong(appName)} as ${emailStrong(role)}.`,
+ `Click the button below to accept the invite and start collaborating.`,
+ ],
+ cta: { label: "Accept invite", url: inviteUrl },
+ // guard:allow-raw-color — email HTML cannot reference CSS theme tokens; mail clients don't support custom properties.
+ brandColor: "#18181B",
+ }),
+ };
+}
+
export default defineAction({
description:
"Invite someone to the active organization by email. Creates a pending invitation. Role 'admin' maps to admin; all other Clips roles collapse to 'member'. Sends an email when a provider is configured.",
@@ -123,24 +154,17 @@ export default defineAction({
const orgName = await fetchOrgName(organizationId);
const inviteUrl = `${baseUrl()}/invite/${token}`;
- const appName = getAppName();
- const { html, text } = renderEmail({
- brandName: appName,
- preheader: `${inviter} invited you to ${orgName} on ${appName}.`,
- heading: `You're invited to join ${orgName}`,
- paragraphs: [
- `${emailStrong(inviter)} invited you to the ${emailStrong(orgName)} organization on ${emailStrong(appName)} as ${emailStrong(role)}.`,
- `Click the button below to accept the invite and start collaborating.`,
- ],
- cta: { label: "Accept invite", url: inviteUrl },
- brandColor: "#18181B",
- });
try {
await sendEmail({
+ ...renderClipsInviteEmail({
+ appName: getAppName(),
+ orgName,
+ inviter,
+ role,
+ inviteUrl,
+ }),
to: args.email,
- subject: `You're invited to ${orgName} on ${appName}`,
- html,
- text,
+ templateId: CLIPS_ORGANIZATION_INVITE_EMAIL_ID,
});
} catch (err) {
console.warn("[invite-member] email send failed:", err);
diff --git a/templates/clips/server/lib/emails.ts b/templates/clips/server/lib/emails.ts
new file mode 100644
index 0000000000..4673ded06b
--- /dev/null
+++ b/templates/clips/server/lib/emails.ts
@@ -0,0 +1,256 @@
+/**
+ * Catalog entries for the transactional emails Clips sends.
+ *
+ * Registered from `server/plugins/transactional-emails.ts` so Dispatch can list
+ * and preview them without the app having sent anything yet.
+ *
+ * Every entry except the organization invite renders through
+ * `renderClipsTransactionalEmail`, so a preview shows the real template rather
+ * than a copy of it.
+ */
+
+import { defineTransactionalEmail } from "@agent-native/core/email-catalog";
+
+import { renderClipsInviteEmail } from "../../actions/invite-member.js";
+import {
+ CLIPS_ACTIVITY_COMMENT_EMAIL_ID,
+ CLIPS_ACTIVITY_REACTION_EMAIL_ID,
+ CLIPS_FIRST_AGENT_VIEW_EMAIL_ID,
+ CLIPS_FIRST_IMPORT_EMAIL_ID,
+ CLIPS_FIRST_VIEW_EMAIL_ID,
+ CLIPS_MONTHLY_RECAP_EMAIL_ID,
+ CLIPS_TWO_CLIPS_EMAIL_ID,
+ CLIPS_UNVIEWED_REMINDER_EMAIL_ID,
+ renderClipsTransactionalEmail,
+ type ClipsTransactionalEmailInput,
+ type ClipsTransactionalEmailRenderOptions,
+} from "./transactional-email-templates.js";
+
+/** Obviously-fake sample data — these render in a preview pane, never send. */
+const PREVIEW_OPTIONS: ClipsTransactionalEmailRenderOptions = {
+ appUrl: "https://example.com",
+};
+const SAMPLE_RECORDING_ID = "rec_sample";
+const SAMPLE_TITLE = "Onboarding walkthrough";
+const SAMPLE_TO = "sam.rivera@example.com";
+
+function preview(input: ClipsTransactionalEmailInput) {
+ return renderClipsTransactionalEmail(input, PREVIEW_OPTIONS);
+}
+
+export const CLIPS_ORGANIZATION_INVITE_EMAIL_ID = "clips.organization-invite";
+
+/**
+ * How the shared Clips sender resolves From and Reply-To for every kind it
+ * renders, so each entry can say so without restating the mechanism.
+ */
+const CLIPS_SENDER =
+ 'From is the configured EMAIL_FROM with the display name "Agent-Native Clips"; on first-party agent-native.com deployments it becomes clips@agent-native.com. Reply-to is hello@agent-native.com.';
+
+let registered = false;
+
+export function registerClipsEmails(): void {
+ if (registered) return;
+ registered = true;
+
+ defineTransactionalEmail({
+ id: CLIPS_FIRST_VIEW_EMAIL_ID,
+ name: "First view on a Clip",
+ trigger:
+ "The background transactional-email sweep finds the first counted view of a Clip by someone other than its owner, recorded after transactional email was switched on. One per Clip.",
+ recipientLabel: "Clip owner",
+ recipient:
+ "The Clip's owner. Suppressed recipient addresses are skipped, and the send is dropped if the owner is no longer the recording's owner at send time.",
+ senderLabel: "Agent-Native Clips",
+ sender: CLIPS_SENDER,
+ preview: () =>
+ preview({
+ kind: "first-view",
+ to: SAMPLE_TO,
+ recordingId: SAMPLE_RECORDING_ID,
+ title: SAMPLE_TITLE,
+ viewerEmail: "alex.chen@example.com",
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CLIPS_UNVIEWED_REMINDER_EMAIL_ID,
+ name: "Unviewed Clip reminder",
+ trigger:
+ "A direct share is 48 hours old and the recipient still has no counted view of that Clip. Re-checked at send time, so a view in the meantime cancels it.",
+ recipientLabel: "Shared-with address",
+ recipient:
+ "The address the Clip was directly shared with. Requires the share to still exist.",
+ senderLabel: "Sharer via Clips",
+ sender:
+ 'Same as the other Clips emails, except the display name becomes " (via Agent-Native Clips)" and reply-to is the sharer\'s own address when it is a valid address, falling back to hello@agent-native.com.',
+ preview: () =>
+ preview({
+ kind: "unviewed-reminder",
+ to: SAMPLE_TO,
+ recordingId: SAMPLE_RECORDING_ID,
+ title: SAMPLE_TITLE,
+ senderEmail: "dana.hill@example.com",
+ senderName: "Dana Hill",
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CLIPS_FIRST_AGENT_VIEW_EMAIL_ID,
+ name: "First agent read of a Clip",
+ trigger:
+ "An AI agent reads one of an owner's Clips for the first time since transactional email was switched on. One per owner, not per Clip.",
+ recipientLabel: "Clip owner",
+ recipient:
+ "The owner of the Clip the agent read. Re-checked at send time against the owner's actual first agent view.",
+ senderLabel: "Agent-Native Clips",
+ sender: CLIPS_SENDER,
+ preview: () =>
+ preview({
+ kind: "first-agent-view",
+ to: SAMPLE_TO,
+ recordingId: SAMPLE_RECORDING_ID,
+ title: SAMPLE_TITLE,
+ agentName: "Claude Code",
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CLIPS_FIRST_IMPORT_EMAIL_ID,
+ name: "First imported video is ready",
+ trigger:
+ "An owner's first imported (rather than recorded) video finishes processing and becomes ready. One per owner.",
+ recipientLabel: "Clip owner",
+ recipient:
+ "The owner of the imported recording, re-checked at send time so a later import does not resend.",
+ senderLabel: "Agent-Native Clips",
+ sender: CLIPS_SENDER,
+ preview: () =>
+ preview({
+ kind: "first-import",
+ to: SAMPLE_TO,
+ recordingId: SAMPLE_RECORDING_ID,
+ title: "Quarterly demo recording",
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CLIPS_MONTHLY_RECAP_EMAIL_ID,
+ name: "Monthly Clips recap",
+ trigger:
+ "Once per owner per calendar month, from 14:00 UTC on the 1st, for owners whose Clips had any human views or agent reads in the closed month. Metrics and the top Clip are recomputed at send time.",
+ recipientLabel: "Clip owner",
+ recipient:
+ "The Clip owner whose audience the recap reports. Suppressed addresses are skipped.",
+ senderLabel: "Agent-Native Clips",
+ sender: CLIPS_SENDER,
+ preview: () =>
+ preview({
+ kind: "monthly-recap",
+ to: SAMPLE_TO,
+ month: "2025-02",
+ humanViews: 42,
+ agentSessions: 7,
+ topClip: {
+ recordingId: SAMPLE_RECORDING_ID,
+ title: SAMPLE_TITLE,
+ thumbnailUrl: "https://example.com/thumbnails/sample.png",
+ durationMs: 214_000,
+ recordedAt: "2025-02-11T16:00:00.000Z",
+ humanViews: 18,
+ agentSessions: 4,
+ },
+ copy: {
+ heroLine: "Your clips were watched 42 times. 7 agents read them.",
+ completionNote: "68% average completion · most stopped at 2:31",
+ agentBreakdown: "4 from Claude Code · 3 unidentified",
+ },
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CLIPS_TWO_CLIPS_EMAIL_ID,
+ name: "Two Clips received",
+ trigger:
+ "A one-time nudge once someone who owns no Clips of their own has had two distinct Clips directly shared with them. The summary line is AI-generated before the job is released to send.",
+ recipientLabel: "Shared-with address",
+ recipient:
+ "The shared-with address. Dropped at send time if they now own a Clip or no longer hold both shares.",
+ senderLabel: "Agent-Native Clips",
+ sender: CLIPS_SENDER,
+ preview: () =>
+ preview({
+ kind: "two-clips",
+ to: SAMPLE_TO,
+ generatedSummary:
+ "Two teammates walked you through the new onboarding flow.",
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CLIPS_ACTIVITY_COMMENT_EMAIL_ID,
+ name: "Clip comment",
+ trigger:
+ "Someone comments or replies on a Clip. Subject and copy differ slightly for a reply; both send under this id.",
+ recipientLabel: "Owner and thread authors",
+ recipient:
+ "The recording owner, plus every prior author in the thread when the comment is a reply. The list is re-checked against the recording's live ACL and filtered by each user's `emailNotifications` preference; the comment's own author never receives it.",
+ senderLabel: "Agent-Native Clips",
+ sender: CLIPS_SENDER,
+ preview: () =>
+ preview({
+ kind: "activity-comment",
+ to: SAMPLE_TO,
+ recordingId: SAMPLE_RECORDING_ID,
+ title: SAMPLE_TITLE,
+ authorEmail: "alex.chen@example.com",
+ authorName: "Alex Chen",
+ content: "The step at 1:20 is the part new hires always miss.",
+ videoTimestampMs: 80_000,
+ isReply: false,
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CLIPS_ACTIVITY_REACTION_EMAIL_ID,
+ name: "Clip reaction",
+ trigger: "A viewer reacts with an emoji on a Clip.",
+ recipientLabel: "Clip owner",
+ recipient:
+ "The recording owner plus any extra recipients the caller passes, re-checked against the recording's live ACL and filtered by each user's `emailNotifications` preference. The reacting viewer never receives it.",
+ senderLabel: "Agent-Native Clips",
+ sender: CLIPS_SENDER,
+ preview: () =>
+ preview({
+ kind: "activity-reaction",
+ to: SAMPLE_TO,
+ recordingId: SAMPLE_RECORDING_ID,
+ title: SAMPLE_TITLE,
+ emoji: "🎉",
+ authorEmail: "alex.chen@example.com",
+ authorName: "Alex Chen",
+ videoTimestampMs: 45_000,
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CLIPS_ORGANIZATION_INVITE_EMAIL_ID,
+ name: "Organization invitation",
+ trigger:
+ "An organization admin runs `invite-member`. Any earlier pending invite for the same address is cancelled first, so a re-invite sends a fresh email with a new token.",
+ recipientLabel: "Invited address",
+ recipient:
+ "The address passed to the action, exactly as typed. One email per invite.",
+ senderLabel: "Default sender",
+ sender:
+ "The configured default sender. This call site sets no `from`, `fromName`, `replyTo`, or `appSender`, so unlike the other Clips emails it does not send as Agent-Native Clips.",
+ preview: () =>
+ renderClipsInviteEmail({
+ appName: "Clips",
+ orgName: "Northwind Design",
+ inviter: "dana.hill@example.com",
+ role: "member",
+ inviteUrl: "https://example.com/invite/sample-token",
+ }),
+ });
+}
diff --git a/templates/clips/server/lib/transactional-email-templates.test.ts b/templates/clips/server/lib/transactional-email-templates.test.ts
index 7c4121dfd5..f08065408c 100644
--- a/templates/clips/server/lib/transactional-email-templates.test.ts
+++ b/templates/clips/server/lib/transactional-email-templates.test.ts
@@ -70,6 +70,7 @@ describe("renderClipsTransactionalEmail", () => {
title: "Imported demo",
},
subject: "Your first imported video is now Agent-Native",
+ templateId: "clips.first-import",
heading: "Your video is ready for more than playback",
cta: "Open your Agent-Native Clip: https://clips.example/r/rec-3",
},
@@ -547,6 +548,7 @@ describe("sendClipsTransactionalEmail", () => {
},
replyTo: "hello@agent-native.com",
timeoutMs: 60_000,
+ templateId: "clips.first-import",
});
});
@@ -578,6 +580,7 @@ describe("sendClipsTransactionalEmail", () => {
},
replyTo: "alex@example.com",
timeoutMs: 60_000,
+ templateId: "clips.unviewed-reminder",
});
});
diff --git a/templates/clips/server/lib/transactional-email-templates.ts b/templates/clips/server/lib/transactional-email-templates.ts
index b9d95d894d..8be1d50390 100644
--- a/templates/clips/server/lib/transactional-email-templates.ts
+++ b/templates/clips/server/lib/transactional-email-templates.ts
@@ -86,6 +86,29 @@ export type ClipsTransactionalEmailInput =
videoTimestampMs?: number | null;
});
+export const CLIPS_FIRST_VIEW_EMAIL_ID = "clips.first-view";
+export const CLIPS_UNVIEWED_REMINDER_EMAIL_ID = "clips.unviewed-reminder";
+export const CLIPS_FIRST_AGENT_VIEW_EMAIL_ID = "clips.first-agent-view";
+export const CLIPS_FIRST_IMPORT_EMAIL_ID = "clips.first-import";
+export const CLIPS_MONTHLY_RECAP_EMAIL_ID = "clips.monthly-recap";
+export const CLIPS_TWO_CLIPS_EMAIL_ID = "clips.two-clips";
+export const CLIPS_ACTIVITY_COMMENT_EMAIL_ID = "clips.activity-comment";
+export const CLIPS_ACTIVITY_REACTION_EMAIL_ID = "clips.activity-reaction";
+
+export const CLIPS_EMAIL_ID_BY_KIND: Record<
+ ClipsTransactionalEmailInput["kind"],
+ string
+> = {
+ "first-view": CLIPS_FIRST_VIEW_EMAIL_ID,
+ "unviewed-reminder": CLIPS_UNVIEWED_REMINDER_EMAIL_ID,
+ "first-agent-view": CLIPS_FIRST_AGENT_VIEW_EMAIL_ID,
+ "first-import": CLIPS_FIRST_IMPORT_EMAIL_ID,
+ "monthly-recap": CLIPS_MONTHLY_RECAP_EMAIL_ID,
+ "two-clips": CLIPS_TWO_CLIPS_EMAIL_ID,
+ "activity-comment": CLIPS_ACTIVITY_COMMENT_EMAIL_ID,
+ "activity-reaction": CLIPS_ACTIVITY_REACTION_EMAIL_ID,
+};
+
export interface RecapTopClipInput {
recordingId: string;
title?: string | null;
@@ -613,6 +636,7 @@ export async function sendClipsTransactionalEmail(
? (validReplyTo(input.senderEmail) ?? FRIENDLY_REPLY_TO)
: FRIENDLY_REPLY_TO,
timeoutMs: EMAIL_SEND_TIMEOUT_MS,
+ templateId: CLIPS_EMAIL_ID_BY_KIND[input.kind],
});
}
diff --git a/templates/clips/server/plugins/transactional-email-catalog.ts b/templates/clips/server/plugins/transactional-email-catalog.ts
new file mode 100644
index 0000000000..06f5b51fd7
--- /dev/null
+++ b/templates/clips/server/plugins/transactional-email-catalog.ts
@@ -0,0 +1,5 @@
+import { registerClipsEmails } from "../lib/emails.js";
+
+export default function registerTransactionalEmailCatalog(): void {
+ registerClipsEmails();
+}
diff --git a/templates/content/server/lib/comment-notifications.ts b/templates/content/server/lib/comment-notifications.ts
index bd29251f35..a9048f4bd9 100644
--- a/templates/content/server/lib/comment-notifications.ts
+++ b/templates/content/server/lib/comment-notifications.ts
@@ -21,6 +21,10 @@ import { and, eq } from "drizzle-orm";
import { CONTENT_USER_PREFS_KEY } from "../../shared/content-user-prefs.js";
import { getDb, schema } from "../db/index.js";
+import {
+ CONTENT_DOCUMENT_COMMENT_EMAIL_ID,
+ CONTENT_DOCUMENT_MENTION_EMAIL_ID,
+} from "./emails.js";
export type DocumentCommentNotificationResult = ActivityNotificationResult;
@@ -70,6 +74,48 @@ export interface DocumentCommentNotificationInput {
isReply: boolean;
}
+export function renderDocumentCommentEmail({
+ actor,
+ title,
+ url,
+ content,
+ isReply,
+ wasMentioned,
+}: {
+ actor: string;
+ title: string;
+ url: string;
+ content: string;
+ isReply: boolean;
+ wasMentioned: boolean;
+}) {
+ const lead = wasMentioned
+ ? `${emailStrong(actor)} mentioned you in a comment on ${emailStrong(title)}.`
+ : isReply
+ ? `${emailStrong(actor)} replied in a comment thread on ${emailStrong(title)}.`
+ : `${emailStrong(actor)} commented on ${emailStrong(title)}.`;
+
+ return {
+ subject: wasMentioned
+ ? `${actor} mentioned you on "${title}"`
+ : isReply
+ ? `${actor} replied to a comment on "${title}"`
+ : `${actor} commented on "${title}"`,
+ ...renderEmail({
+ preheader: `${actor} commented on ${title}.`,
+ heading: wasMentioned
+ ? "You were mentioned"
+ : isReply
+ ? "New reply on your document"
+ : "New comment",
+ paragraphs: [lead, `"${excerpt(content)}"`],
+ cta: { label: "Open document", url },
+ footer:
+ "You received this because you own, were mentioned in, or participated in this thread. Turn these off in Documents settings.",
+ }),
+ };
+}
+
export async function notifyDocumentComment(
input: DocumentCommentNotificationInput,
): Promise {
@@ -112,34 +158,19 @@ async function deliverDocumentCommentEmails(
logLabel: LOG_LABEL,
send: async (to) => {
const wasMentioned = mentioned.has(to);
- const lead = wasMentioned
- ? `${emailStrong(actor)} mentioned you in a comment on ${emailStrong(title)}.`
- : input.isReply
- ? `${emailStrong(actor)} replied in a comment thread on ${emailStrong(title)}.`
- : `${emailStrong(actor)} commented on ${emailStrong(title)}.`;
-
- const { html, text } = renderEmail({
- preheader: `${actor} commented on ${title}.`,
- heading: wasMentioned
- ? "You were mentioned"
- : input.isReply
- ? "New reply on your document"
- : "New comment",
- paragraphs: [lead, `"${excerpt(input.content)}"`],
- cta: { label: "Open document", url },
- footer:
- "You received this because you own, were mentioned in, or participated in this thread. Turn these off in Documents settings.",
- });
-
await sendEmail({
+ ...renderDocumentCommentEmail({
+ actor,
+ title,
+ url,
+ content: input.content,
+ isReply: input.isReply,
+ wasMentioned,
+ }),
to,
- subject: wasMentioned
- ? `${actor} mentioned you on "${title}"`
- : input.isReply
- ? `${actor} replied to a comment on "${title}"`
- : `${actor} commented on "${title}"`,
- html,
- text,
+ templateId: wasMentioned
+ ? CONTENT_DOCUMENT_MENTION_EMAIL_ID
+ : CONTENT_DOCUMENT_COMMENT_EMAIL_ID,
});
},
});
diff --git a/templates/content/server/lib/emails.ts b/templates/content/server/lib/emails.ts
new file mode 100644
index 0000000000..62688eecba
--- /dev/null
+++ b/templates/content/server/lib/emails.ts
@@ -0,0 +1,70 @@
+/**
+ * Catalog entries for the transactional emails Documents sends.
+ *
+ * Registered from `server/plugins/transactional-emails.ts` so Dispatch can list
+ * and preview them without the app having sent anything yet.
+ */
+
+import { defineTransactionalEmail } from "@agent-native/core/email-catalog";
+
+import { renderDocumentCommentEmail } from "./comment-notifications.js";
+
+/** Obviously-fake sample data — these render in a preview pane, never send. */
+const SAMPLE_TITLE = "Q3 launch brief";
+const SAMPLE_URL = "https://example.com/page/doc_sample";
+const SAMPLE_COMMENT =
+ "Can we tighten the second paragraph? It repeats the intro.";
+
+export const CONTENT_DOCUMENT_COMMENT_EMAIL_ID = "content.document-comment";
+export const CONTENT_DOCUMENT_MENTION_EMAIL_ID = "content.document-mention";
+
+let registered = false;
+
+export function registerContentEmails(): void {
+ if (registered) return;
+ registered = true;
+
+ defineTransactionalEmail({
+ id: CONTENT_DOCUMENT_COMMENT_EMAIL_ID,
+ name: "Document comment",
+ trigger:
+ "Someone posts a comment or a thread reply on a document. Sent to recipients who were not mentioned in it; the copy and subject differ slightly for a reply.",
+ recipientLabel: "Owner and thread authors",
+ recipient:
+ "The document owner, plus every prior author in the thread when the new comment is a reply. The list is re-checked against the document's live ACL and filtered by each user's `emailNotifications` preference; the comment's own author never receives it.",
+ senderLabel: "Default sender",
+ sender:
+ "The configured default sender. This call site sets no `from`, `fromName`, `replyTo`, or `appSender`.",
+ preview: () =>
+ renderDocumentCommentEmail({
+ actor: "Sam Rivera",
+ title: SAMPLE_TITLE,
+ url: SAMPLE_URL,
+ content: SAMPLE_COMMENT,
+ isReply: false,
+ wasMentioned: false,
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: CONTENT_DOCUMENT_MENTION_EMAIL_ID,
+ name: "Document mention",
+ trigger:
+ "A comment or reply mentions someone by email. Sent instead of the plain comment notification to each mentioned recipient.",
+ recipientLabel: "Mentioned users",
+ recipient:
+ "The mentioned addresses supplied by the caller, re-checked against the document's live ACL and filtered by each user's `emailNotifications` preference.",
+ senderLabel: "Default sender",
+ sender:
+ "The configured default sender. This call site sets no `from`, `fromName`, `replyTo`, or `appSender`.",
+ preview: () =>
+ renderDocumentCommentEmail({
+ actor: "Sam Rivera",
+ title: SAMPLE_TITLE,
+ url: SAMPLE_URL,
+ content: SAMPLE_COMMENT,
+ isReply: false,
+ wasMentioned: true,
+ }),
+ });
+}
diff --git a/templates/content/server/plugins/transactional-emails.ts b/templates/content/server/plugins/transactional-emails.ts
new file mode 100644
index 0000000000..37a9ac621e
--- /dev/null
+++ b/templates/content/server/plugins/transactional-emails.ts
@@ -0,0 +1,5 @@
+import { registerContentEmails } from "../lib/emails.js";
+
+export default function registerTransactionalEmails(): void {
+ registerContentEmails();
+}
diff --git a/templates/dispatch/app/routes/transactional-email.$appId.$id.tsx b/templates/dispatch/app/routes/transactional-email.$appId.$id.tsx
new file mode 100644
index 0000000000..be1527d6f4
--- /dev/null
+++ b/templates/dispatch/app/routes/transactional-email.$appId.$id.tsx
@@ -0,0 +1,4 @@
+export {
+ default,
+ meta,
+} from "@agent-native/dispatch/routes/pages/transactional-email.$appId.$id";
diff --git a/templates/dispatch/app/routes/transactional-email.tsx b/templates/dispatch/app/routes/transactional-email.tsx
new file mode 100644
index 0000000000..72a0cee6bf
--- /dev/null
+++ b/templates/dispatch/app/routes/transactional-email.tsx
@@ -0,0 +1,4 @@
+export {
+ default,
+ meta,
+} from "@agent-native/dispatch/routes/pages/transactional-email";
diff --git a/templates/forms/server/lib/emails.ts b/templates/forms/server/lib/emails.ts
new file mode 100644
index 0000000000..ea22583889
--- /dev/null
+++ b/templates/forms/server/lib/emails.ts
@@ -0,0 +1,52 @@
+/**
+ * Catalog entries for the transactional emails Forms sends.
+ *
+ * Registered from `server/plugins/transactional-emails.ts` so Dispatch can list
+ * and preview them without the app having sent anything yet.
+ */
+
+import { defineTransactionalEmail } from "@agent-native/core/email-catalog";
+
+import { renderNewResponseEmail } from "./response-email.js";
+
+export const FORMS_NEW_RESPONSE_EMAIL_ID = "forms.new-response";
+
+let registered = false;
+
+export function registerFormsEmails(): void {
+ if (registered) return;
+ registered = true;
+
+ defineTransactionalEmail({
+ id: FORMS_NEW_RESPONSE_EMAIL_ID,
+ name: "New form response",
+ trigger:
+ "A response is submitted and persisted for a form whose settings have `emailOnNewResponses` enabled. Delivery is best-effort: a send failure never rejects the submission.",
+ recipientLabel: "Form owner",
+ recipient:
+ "The form's `ownerEmail`, and only that address — the respondent is never emailed. Skipped when the form has no owner address.",
+ senderLabel: "Default sender",
+ sender:
+ "The configured default sender. This call site sets no `from`, `fromName`, `replyTo`, or `appSender`, so a reply goes to the sending mailbox rather than to the respondent.",
+ preview: () =>
+ renderNewResponseEmail({
+ formTitle: "Beta feedback",
+ fields: [
+ { id: "name", type: "text", label: "Name", required: true },
+ { id: "email", type: "email", label: "Email", required: true },
+ {
+ id: "notes",
+ type: "textarea",
+ label: "What should we fix first?",
+ required: false,
+ },
+ ],
+ data: {
+ name: "Sam Rivera",
+ email: "sam.rivera@example.com",
+ notes: "The export button is hard to find on mobile.",
+ },
+ submittedAt: "2025-03-04T17:20:00.000Z",
+ }),
+ });
+}
diff --git a/templates/forms/server/lib/response-email.ts b/templates/forms/server/lib/response-email.ts
index 9b70427b25..ab40312317 100644
--- a/templates/forms/server/lib/response-email.ts
+++ b/templates/forms/server/lib/response-email.ts
@@ -1,6 +1,7 @@
import { emailStrong, renderEmail, sendEmail } from "@agent-native/core/server";
import type { FormField } from "../../shared/types.js";
+import { FORMS_NEW_RESPONSE_EMAIL_ID } from "./emails.js";
export interface NewResponseEmailArgs {
to: string;
@@ -61,5 +62,6 @@ export async function sendNewResponseEmail(
await sendEmail({
to: args.to,
...renderNewResponseEmail(args),
+ templateId: FORMS_NEW_RESPONSE_EMAIL_ID,
});
}
diff --git a/templates/forms/server/plugins/transactional-emails.ts b/templates/forms/server/plugins/transactional-emails.ts
new file mode 100644
index 0000000000..96e0f3b09a
--- /dev/null
+++ b/templates/forms/server/plugins/transactional-emails.ts
@@ -0,0 +1,5 @@
+import { registerFormsEmails } from "../lib/emails.js";
+
+export default function registerTransactionalEmails(): void {
+ registerFormsEmails();
+}
diff --git a/templates/plan/actions/request-plan-access.ts b/templates/plan/actions/request-plan-access.ts
index 8a7bfe0c1e..f01e34a3e7 100644
--- a/templates/plan/actions/request-plan-access.ts
+++ b/templates/plan/actions/request-plan-access.ts
@@ -22,6 +22,8 @@ import {
} from "../server/lib/local-identity.js";
import { newId, nowIso, planPath, writeEvent } from "../server/plans.js";
+export const PLAN_ACCESS_REQUEST_EMAIL_ID = "plan.access-request";
+
function httpError(message: string, statusCode: number): Error {
return Object.assign(new Error(message), { statusCode });
}
@@ -49,6 +51,28 @@ function absolutePlanUrl(planId: string, kind: "plan" | "recap"): string {
}
}
+export function renderPlanAccessRequestEmail(input: {
+ requesterName: string;
+ requesterEmail: string;
+ planTitle: string;
+ url: string;
+}) {
+ const subject = `${input.requesterName} requested access to "${input.planTitle}"`;
+ return {
+ subject,
+ ...renderEmail({
+ preheader: subject,
+ heading: "Access request",
+ paragraphs: [
+ `${emailStrong(input.requesterName)} (${emailStrong(input.requesterEmail)}) requested access to ${emailStrong(input.planTitle)}.`,
+ "Open the plan and use Share to grant access if this request should be approved.",
+ ],
+ cta: { label: "Open plan", url: input.url },
+ footer: "You received this because you own this Agent-Native Plan.",
+ }),
+ };
+}
+
async function notifyOwner(input: {
planId: string;
planKind: "plan" | "recap";
@@ -62,19 +86,16 @@ async function notifyOwner(input: {
return false;
}
- const url = absolutePlanUrl(input.planId, input.planKind);
- const subject = `${input.requesterName} requested access to "${input.planTitle}"`;
- const { html, text } = renderEmail({
- preheader: subject,
- heading: "Access request",
- paragraphs: [
- `${emailStrong(input.requesterName)} (${emailStrong(input.requesterEmail)}) requested access to ${emailStrong(input.planTitle)}.`,
- "Open the plan and use Share to grant access if this request should be approved.",
- ],
- cta: { label: "Open plan", url },
- footer: "You received this because you own this Agent-Native Plan.",
+ await sendEmail({
+ ...renderPlanAccessRequestEmail({
+ requesterName: input.requesterName,
+ requesterEmail: input.requesterEmail,
+ planTitle: input.planTitle,
+ url: absolutePlanUrl(input.planId, input.planKind),
+ }),
+ to: input.ownerEmail,
+ templateId: PLAN_ACCESS_REQUEST_EMAIL_ID,
});
- await sendEmail({ to: input.ownerEmail, subject, html, text });
return true;
}
diff --git a/templates/plan/server/lib/comment-notifications.spec.ts b/templates/plan/server/lib/comment-notifications.spec.ts
index cc956ed82b..a7974b158a 100644
--- a/templates/plan/server/lib/comment-notifications.spec.ts
+++ b/templates/plan/server/lib/comment-notifications.spec.ts
@@ -260,6 +260,7 @@ describe("plan comment notification recipients", () => {
subject: `Reviewer commented on "Launch Plan"`,
html: "
Email
",
text: "Email",
+ templateId: "plan.plan-comment",
});
});
diff --git a/templates/plan/server/lib/comment-notifications.ts b/templates/plan/server/lib/comment-notifications.ts
index 7b56072b0c..a4d160032c 100644
--- a/templates/plan/server/lib/comment-notifications.ts
+++ b/templates/plan/server/lib/comment-notifications.ts
@@ -14,6 +14,8 @@ import {
import type { PlanBundle, PlanComment } from "../../shared/types.js";
import { getDb, schema } from "../db/index.js";
+export const PLAN_COMMENT_EMAIL_ID = "plan.plan-comment";
+
type CommentNotificationInput = {
bundle: PlanBundle;
insertedCommentIds: string[];
@@ -205,40 +207,64 @@ export function planCommentNotificationRecipients(input: {
return Array.from(recipients.values());
}
-async function sendPlanCommentNotification(input: {
- recipient: NotificationRecipient;
- comment: PlanComment;
+export function renderPlanCommentEmail(input: {
+ actor: string;
+ app: string;
planTitle: string;
- planId: string;
+ planUrl: string;
+ message: string;
+ isReply: boolean;
+ reason: NotificationRecipient["reason"];
}) {
- const actor = actorName(input.comment);
- const app = appName();
- const isReply = Boolean(input.comment.parentCommentId);
- const subject = isReply
- ? `${actor} replied to a comment on "${input.planTitle}"`
- : `${actor} commented on "${input.planTitle}"`;
const actionText =
- input.recipient.reason === "mention"
+ input.reason === "mention"
? "mentioned you in a comment on"
- : input.recipient.reason === "plan-owner"
+ : input.reason === "plan-owner"
? "left a comment on your plan"
: "replied in a comment thread you participated in";
- const { html, text } = renderEmail({
- preheader: `${actor} ${actionText} on ${app}.`,
- heading: isReply ? "New reply on your plan" : "New comment on your plan",
- paragraphs: [
- `${emailStrong(actor)} ${actionText} ${emailStrong(input.planTitle)}.`,
- `Comment: "${commentExcerpt(input.comment.message)}"`,
- ],
- cta: { label: "Open plan", url: planUrl(input.planId) },
- footer:
- input.recipient.reason === "plan-owner"
- ? "You received this because you own this plan."
- : input.recipient.reason === "mention"
- ? "You received this because you were mentioned in this comment."
- : "You received this because you participated in this comment thread.",
+ return {
+ subject: input.isReply
+ ? `${input.actor} replied to a comment on "${input.planTitle}"`
+ : `${input.actor} commented on "${input.planTitle}"`,
+ ...renderEmail({
+ preheader: `${input.actor} ${actionText} on ${input.app}.`,
+ heading: input.isReply
+ ? "New reply on your plan"
+ : "New comment on your plan",
+ paragraphs: [
+ `${emailStrong(input.actor)} ${actionText} ${emailStrong(input.planTitle)}.`,
+ `Comment: "${commentExcerpt(input.message)}"`,
+ ],
+ cta: { label: "Open plan", url: input.planUrl },
+ footer:
+ input.reason === "plan-owner"
+ ? "You received this because you own this plan."
+ : input.reason === "mention"
+ ? "You received this because you were mentioned in this comment."
+ : "You received this because you participated in this comment thread.",
+ }),
+ };
+}
+
+async function sendPlanCommentNotification(input: {
+ recipient: NotificationRecipient;
+ comment: PlanComment;
+ planTitle: string;
+ planId: string;
+}) {
+ await sendEmail({
+ ...renderPlanCommentEmail({
+ actor: actorName(input.comment),
+ app: appName(),
+ planTitle: input.planTitle,
+ planUrl: planUrl(input.planId),
+ message: input.comment.message,
+ isReply: Boolean(input.comment.parentCommentId),
+ reason: input.recipient.reason,
+ }),
+ to: input.recipient.email,
+ templateId: PLAN_COMMENT_EMAIL_ID,
});
- await sendEmail({ to: input.recipient.email, subject, html, text });
}
export async function notifyPlanCommentRecipients({
diff --git a/templates/plan/server/lib/emails.ts b/templates/plan/server/lib/emails.ts
new file mode 100644
index 0000000000..7b5752fc43
--- /dev/null
+++ b/templates/plan/server/lib/emails.ts
@@ -0,0 +1,67 @@
+/**
+ * Catalog entries for the transactional emails Plan sends.
+ *
+ * Registered from `server/plugins/transactional-emails.ts` so Dispatch can list
+ * and preview them without the app having sent anything yet.
+ */
+
+import { defineTransactionalEmail } from "@agent-native/core/email-catalog";
+
+import {
+ PLAN_ACCESS_REQUEST_EMAIL_ID,
+ renderPlanAccessRequestEmail,
+} from "../../actions/request-plan-access.js";
+import {
+ PLAN_COMMENT_EMAIL_ID,
+ renderPlanCommentEmail,
+} from "./comment-notifications.js";
+
+let registered = false;
+
+export function registerPlanEmails(): void {
+ if (registered) return;
+ registered = true;
+
+ defineTransactionalEmail({
+ id: PLAN_COMMENT_EMAIL_ID,
+ name: "Plan comment",
+ trigger:
+ "A human (never the agent) posts a comment or reply on a plan or recap. The subject changes for a reply and the body changes with why the recipient was picked; all variants send under this id.",
+ recipientLabel: "Owner, mentions, authors",
+ recipient:
+ "The plan owner, everyone mentioned in the comment, and — for a reply — every other human author in the same thread. The comment's own author, synthetic QA addresses, and the owner when the comment mentions the source author are all dropped. One email per remaining address.",
+ senderLabel: "Default sender",
+ sender:
+ "The configured default sender. This call site sets no `from`, `fromName`, `replyTo`, or `appSender`.",
+ preview: () =>
+ renderPlanCommentEmail({
+ actor: "Sam Rivera",
+ app: "Agent-Native Plan",
+ planTitle: "Checkout rewrite",
+ planUrl: "https://example.com/plans/plan_sample",
+ message: "Can we split the migration into two deploys?",
+ isReply: false,
+ reason: "plan-owner",
+ }),
+ });
+
+ defineTransactionalEmail({
+ id: PLAN_ACCESS_REQUEST_EMAIL_ID,
+ name: "Plan access request",
+ trigger:
+ "A signed-in user who cannot resolve access calls `request-plan-access` on a private plan URL. Skipped when email is not configured or the requester is the owner.",
+ recipientLabel: "Plan owner",
+ recipient:
+ "The plan's `ownerEmail` column. Anonymous public viewers and guest author identities cannot reach this path.",
+ senderLabel: "Default sender",
+ sender:
+ "The configured default sender. This call site sets no `from`, `fromName`, `replyTo`, or `appSender`, so the owner cannot reply straight to the requester.",
+ preview: () =>
+ renderPlanAccessRequestEmail({
+ requesterName: "Sam Rivera",
+ requesterEmail: "sam.rivera@example.com",
+ planTitle: "Checkout rewrite",
+ url: "https://example.com/plans/plan_sample",
+ }),
+ });
+}
diff --git a/templates/plan/server/plugins/transactional-emails.ts b/templates/plan/server/plugins/transactional-emails.ts
new file mode 100644
index 0000000000..5190cbd818
--- /dev/null
+++ b/templates/plan/server/plugins/transactional-emails.ts
@@ -0,0 +1,5 @@
+import { registerPlanEmails } from "../lib/emails.js";
+
+export default function registerTransactionalEmails(): void {
+ registerPlanEmails();
+}
diff --git a/templates/slides/server/lib/comment-notifications.ts b/templates/slides/server/lib/comment-notifications.ts
index 9d480bddf8..31b0d88dad 100644
--- a/templates/slides/server/lib/comment-notifications.ts
+++ b/templates/slides/server/lib/comment-notifications.ts
@@ -21,6 +21,7 @@ import { and, eq } from "drizzle-orm";
import { getDeckUrl } from "../../actions/_app-url.js";
import { SLIDES_USER_PREFS_KEY } from "../../shared/slides-user-prefs.js";
import { getDb, schema } from "../db/index.js";
+import { SLIDES_DECK_COMMENT_EMAIL_ID } from "./emails.js";
/**
* `deck-missing` stays distinct from `no-recipients`: one means the deck could
@@ -99,6 +100,41 @@ async function threadParticipants(
return rows.map((row) => row.authorEmail);
}
+export function renderDeckCommentEmail({
+ actor,
+ title,
+ url,
+ content,
+ isReply,
+}: {
+ actor: string;
+ title: string;
+ url: string;
+ content: string;
+ isReply: boolean;
+}) {
+ return {
+ subject: isReply
+ ? `${actor} replied to a comment on "${title}"`
+ : `${actor} commented on "${title}"`,
+ ...renderEmail({
+ preheader: isReply
+ ? `${actor} replied to a comment on ${title}.`
+ : `${actor} commented on ${title}.`,
+ heading: isReply ? "New reply on your deck" : "New comment",
+ paragraphs: [
+ isReply
+ ? `${emailStrong(actor)} replied in a comment thread on ${emailStrong(title)}.`
+ : `${emailStrong(actor)} commented on ${emailStrong(title)}.`,
+ `"${excerpt(content)}"`,
+ ],
+ cta: { label: "Open deck", url },
+ footer:
+ "You received this because you own or participated in this thread. Turn these off in Slides settings.",
+ }),
+ };
+}
+
export async function notifyDeckComment(input: {
deckId: string;
slideId: string;
@@ -153,29 +189,16 @@ async function deliverDeckCommentEmails(input: {
preferenceKey: SLIDES_USER_PREFS_KEY,
logLabel: LOG_LABEL,
send: async (to) => {
- const { html, text } = renderEmail({
- preheader: input.isReply
- ? `${actor} replied to a comment on ${deck.title}.`
- : `${actor} commented on ${deck.title}.`,
- heading: input.isReply ? "New reply on your deck" : "New comment",
- paragraphs: [
- input.isReply
- ? `${emailStrong(actor)} replied in a comment thread on ${emailStrong(deck.title)}.`
- : `${emailStrong(actor)} commented on ${emailStrong(deck.title)}.`,
- `"${excerpt(input.content)}"`,
- ],
- cta: { label: "Open deck", url },
- footer:
- "You received this because you own or participated in this thread. Turn these off in Slides settings.",
- });
-
await sendEmail({
+ ...renderDeckCommentEmail({
+ actor,
+ title: deck.title,
+ url,
+ content: input.content,
+ isReply: input.isReply,
+ }),
to,
- subject: input.isReply
- ? `${actor} replied to a comment on "${deck.title}"`
- : `${actor} commented on "${deck.title}"`,
- html,
- text,
+ templateId: SLIDES_DECK_COMMENT_EMAIL_ID,
});
},
});
diff --git a/templates/slides/server/lib/emails.ts b/templates/slides/server/lib/emails.ts
new file mode 100644
index 0000000000..120268c794
--- /dev/null
+++ b/templates/slides/server/lib/emails.ts
@@ -0,0 +1,40 @@
+/**
+ * Catalog entries for the transactional emails Slides sends.
+ *
+ * Registered from `server/plugins/transactional-emails.ts` so Dispatch can list
+ * and preview them without the app having sent anything yet.
+ */
+
+import { defineTransactionalEmail } from "@agent-native/core/email-catalog";
+
+import { renderDeckCommentEmail } from "./comment-notifications.js";
+
+export const SLIDES_DECK_COMMENT_EMAIL_ID = "slides.deck-comment";
+
+let registered = false;
+
+export function registerSlidesEmails(): void {
+ if (registered) return;
+ registered = true;
+
+ defineTransactionalEmail({
+ id: SLIDES_DECK_COMMENT_EMAIL_ID,
+ name: "Deck comment",
+ trigger:
+ "Someone posts a comment or a thread reply on a slide. Subject and copy differ slightly for a reply; both send under this id.",
+ recipientLabel: "Deck owner and authors",
+ recipient:
+ "The deck owner, plus every prior author in the thread when the new comment is a reply. The list is re-checked against the deck's live ACL and filtered by each user's `emailNotifications` preference; the comment's own author never receives it.",
+ senderLabel: "Default sender",
+ sender:
+ "The configured default sender. This call site sets no `from`, `fromName`, `replyTo`, or `appSender`.",
+ preview: () =>
+ renderDeckCommentEmail({
+ actor: "Sam Rivera",
+ title: "Series A narrative",
+ url: "https://example.com/decks/deck_sample?slide=3",
+ content: "Slide 3 needs the updated revenue chart before Thursday.",
+ isReply: false,
+ }),
+ });
+}
diff --git a/templates/slides/server/plugins/transactional-emails.ts b/templates/slides/server/plugins/transactional-emails.ts
new file mode 100644
index 0000000000..01fb862c10
--- /dev/null
+++ b/templates/slides/server/plugins/transactional-emails.ts
@@ -0,0 +1,5 @@
+import { registerSlidesEmails } from "../lib/emails.js";
+
+export default function registerTransactionalEmails(): void {
+ registerSlidesEmails();
+}