Notifications and integrations
Every change in the CMS is recorded as an action that your server can react to, like emailing a team when a page goes live. You can also hook up an external translation service to export strings and import translated results.
Actions
Each action includes a name (like doc.publish, doc.save, release.publish, or doc.comment.add), the email of the user who triggered it (by, or system for scheduled jobs), a timestamp, and metadata such as docId. Actions are saved at Projects/<id>/ActionLogs in Firestore and shown in the CMS action log.
The onAction callback runs on the server for every action. It isn't awaited, so keep it to fast, fire-and-forget work:
// @/root.config.ts
cmsPlugin({
// ...
onAction: (action) => {
if (action.action === 'doc.publish') {
console.log(`${action.by} published ${action.metadata?.docId}`);
}
},
}),
Plugins and custom server code can log their own actions using logAction() on RootCMSClient. Custom actions are stored like built-in ones, so they appear in the action log and on the CMS home page, and they trigger onAction and notification services. Give them your own prefix (like inventory.sync) to avoid colliding with built-in names and to make wildcard matching like inventory.* easy.
On the home page, recent actions render as short sentences: who did it, what they did, and what they acted on. Pass label to customize the middle phrase:
// @/plugins/inventory.ts
import type {RootConfig} from '@blinkk/root';
import {RootCMSClient} from '@blinkk/root-cms';
export async function logInventorySync(
rootConfig: RootConfig,
options: {userEmail: string; feedId: string; skuCount: number}
) {
const {userEmail, feedId, skuCount} = options;
const cmsClient = new RootCMSClient(rootConfig);
await cmsClient.logAction('inventory.sync', {
by: userEmail,
label: 'synced inventory from',
metadata: {feedId, skuCount},
links: [
{label: 'View feed', url: `https://example.com/feeds/${feedId}`},
],
});
}
That renders as "Ada Lin synced inventory from warehouse-feed". Because the user's name comes from by, write label as a lowercase phrase with no trailing period. The target at the end is pulled from metadata: either a key the CMS recognizes (like docId) or the first key ending in Id alphabetically. If there's no matching key, the label stands on its own, like "rebuilt the search index".
Pass the user's email as by to display their name and avatar. If you omit it, the action is attributed to system and starts with "System". Any other string is displayed as-is next to a clock icon.
Expanding a row shows all of the action's metadata, a button for each entry in links, and the raw action name. Known keys like docId, releaseId, datasourceId, and assetId also link straight to those items.
If you omit label, the row falls back to the action name, like "Ada Lin logged inventory.sync for warehouse-feed". Labels are stored on each action when it's logged, so older entries keep whatever they were recorded with. In onAction handlers, the label is available on action.label, while the full action log continues to display raw names and metadata.
Keep in mind that an email notification service without an actions filter emails on every action, including custom ones, so set an explicit list if you log custom actions frequently. From code running inside the CMS UI, POST the same fields (action, label, metadata, and links) to /cms/api/actions.log to record an action as the signed-in user.
Notification services
To send notifications, register services in the notifications option. Each service defines an id, a label, and an async onAction(ctx, action) handler that decides which actions to act on. ctx provides rootConfig, a cmsClient, and the user who triggered the action. Here's an example that posts to a Slack webhook:
// @/root.config.ts
cmsPlugin({
// ...
notifications: [
{
id: 'slack',
label: 'Slack',
onAction: async (ctx, action) => {
if (action.action !== 'doc.publish') {
return;
}
await fetch(process.env.SLACK_WEBHOOK_URL!, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
text: `${action.by} published ${action.metadata?.docId}`,
}),
});
return {status: 'success'};
},
},
],
}),
Handlers can return {status: 'success' | 'info' | 'error', message} to report their result. Any errors are logged without disrupting the action or other notification services.
Email notifications
emailNotifications() is a built-in service that emails recipients when matching actions occur. actions accepts wildcard patterns (where * matches anything), and to can be a static list or a function that computes recipients per action:
// @/root.config.ts
import {
cmsPlugin,
commentEmailNotifications,
emailNotifications,
} from '@blinkk/root-cms/plugin';
cmsPlugin({
// ...
notifications: [
emailNotifications({
actions: ['doc.publish', 'release.*'],
to: ['web-team@example.com'],
template: {
subject: '[My Site] {action} by {by}',
body: '{by} ran {action} on {metadata.docId}.',
},
emailService: 'https://my-email-service.appspot.com',
}),
commentEmailNotifications({
emailService: 'https://my-email-service.appspot.com',
}),
],
}),
Templates interpolate {placeholder} tokens from the action, including nested paths like {metadata.docId}, and support subject, plain-text body, and html. If you omit a template, Root.js sends a default summary of the action. For complete control, pass a function that builds the email. You can also use filter to skip certain actions (like bot accounts) and transformData to shape the data passed to the template.
commentEmailNotifications() notifies anyone @mentioned in a field comment, plus everyone already in the thread, whenever a comment is added, resolved, or reopened. Links point to rootConfig.domain unless you override them with cmsUrl.
Delivering email
Emails are queued in Firestore at Projects/<id>/Emails and delivered by the Root.js email service, a small App Engine app (apps/root-services in the Root.js repo) that drains the queue using the App Engine Mail API. Because it only reads the queue in its own Google Cloud project, deploy it to the same project as your Firestore database. Set emailService to its URL so new emails go out immediately, and schedule a cron job to hit /_/send_emails?projectId=<id> every few minutes to catch any stragglers.
The App Engine Mail API caps delivery at 100 recipients per day and 8 per minute, counting each recipient individually. Emails over the quota fail and aren't retried, so send team alerts to a Google Group (which counts as one recipient) instead of listing everyone individually. If you need higher volume, send through a provider like SendGrid using a custom notification service.
By default, emails come from noreply@<project-id>.appspotmail.com; any custom from address must be an authorized sender for the Mail API. Set expireAfterMinutes to drop stale emails instead of sending them late.
Your own server code can queue emails through the same pipeline with cmsClient.sendEmail({to, subject, body, htmlBody}).
You can also let a coding agent handle the setup. Paste this prompt in your project:
Set up email notifications for our CMS. Follow the instructions at
https://rootjs.dev/skills/root-cms-email-setup.md
The agent asks who should receive which notifications, deploys the email service to App Engine, sets up the required Firestore index and scheduled job, and adds ready-to-use templates for releases, publishes, publishing locks, and comments in cms/emails.ts. It confirms before creating or deploying anything and finishes by sending a test email. You can also install the skill locally as root-cms-email-setup with root-cms skill.install.
Translation services
To integrate a translation platform like Crowdin or Smartling, register a service in the translations option. It shows up in the Import and Export menus of a doc's localization modal. onExport receives the doc's strings and current translations, and onImport returns translated rows to merge back into the CMS:
// @/root.config.ts
cmsPlugin({
// ...
translations: [
{
id: 'my-tms',
label: 'My TMS',
onExport: async (ctx, rows) => {
// rows: [{source, translations: {de: '...', fr: '...'}}, ...]
const job = await myTms.upload(ctx.docId, rows);
return {
status: 'success',
message: `Sent ${rows.length} strings.`,
link: {url: job.url, label: 'Open in My TMS'},
};
},
onImport: async (ctx) => {
return await myTms.download(ctx.docId, ctx.translationLanguages);
},
},
],
}),
ctx includes the doc's docId, the project's locales, and its translationLanguages (the keys used in translations; see i18n.translationLanguages in root.config.ts). Either handler can return a title, message, link, and status to display a notification, and onImport can return that notification object instead of rows when there's nothing to import.
Use excludeLocalesFromTranslations to omit specific locales from all imports and exports, including CSV and Google Sheets. It accepts patterns like ['ALL_*'], which is handy for pseudo-locales that don't get translated.