Brightspot CMS Developer Guide
Brightspot CMS Developer Guide
Developer guide

Formatting notification messages

The Notification system requires that all subscriptions come with default message formats for both plain text and HTML, and they should contain all of the relevant information a subscriber of some event might care about. Furthermore, it is common practice to specify a custom presentation for the various notifications. As such, Brightspot provides the MessageFormatter class to customize a notification’s presentation over a given delivery option.

public abstract class MessageFormatter<
        S extends Subscription<C>,
        C extends Recordable,
        D extends DeliveryOption<M>,
        M extends Message
        > extends Record {

    public abstract M format(MessageContext<S, C> messageContext, D deliveryOption);


Each message formatter implementation is specific to a type of subscription and a type of delivery option. This means that if you want a custom message format for two different subscription types across three different delivery options, you could have a total of six message formatter implementations. All you need to do is create the classes that you need with the correct Java generics typing, and Brightspot will take care of the rest. Which message formatters get applied is controlled editorially in Brightspot through the global settings.

Each delivery option delivers a specific message type. See the mapping below as a reference.

package com.psddev.cms.notification;





The following snippet is a custom formatter that uses a custom logger, forces the log level to always be a WARNING, and changes the log message.

import com.psddev.cms.notification.MessageContext;
import com.psddev.cms.notification.MessageFormatter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ToolUserAuthLogMessageFormatter
    extends MessageFormatter<ToolUserAuthSubscription, ToolUserAuthEvent, LogDeliveryOption, LogMessage> {

    private static final Logger LOGGER = LoggerFactory.getLogger(ToolUserAuthLogMessageFormatter.class);

    public LogMessage format(
        MessageContext<ToolUserAuthSubscription, ToolUserAuthEvent> messageContext,
        LogDeliveryOption deliveryOption) {

        ToolUserAuthEvent context = messageContext.getContext();
        ToolUserAuthAction action = context.getAction();

        String receiverLabel = messageContext.getReceiver().getReceiverLabel();
        String authUserLabel = context.getUserLabel();
        String actionLabel;

        switch (action) {
            case LOGIN:
                actionLabel = "logged in to";
            case LOGOUT:
                actionLabel = "logged out of";
                return null;

        String message = String.format("%s was notified that %s %s the CMS", receiverLabel, authUserLabel, actionLabel);

        return new LogMessage(messageContext, LOGGER, LogLevel.WARN, message);

The only special element honored by the built-in delivery options is the <content> element, which contains a data-id attribute corresponding to the UUID of an item in the database. Delivery options will search for these elements and convert them into a delivery-option-specific link that opens the item in the content edit page.

Previous Topic
Custom subscriptions
Next Topic
External Types
Was this topic helpful?
Thanks for your feedback.
The elements that get you up and running in a matter of days, from pre-built content types, to modules, to landing pages.

Content types
Landing pages
Everything you need to manage and administer content within Brightspot CMS, including plug-and-play integrations.

Admin configurations
A guide for installing, supporting and administering code on the Brightspot platform, including integrations requiring developer support to use.

Field types
Content modeling
Rich-text elements