A NotificationHandler is responsible for building and sending the message. For example, a
typical use case is for the NotificationHandler to use a MessageBuilder to convert the
NotificationRequest.data
to a Notification.messageBody
.
Each handler must implement four methods.
canHandleDeliveryType(…) returns true if this Handler should be used for the passed in
delivery type which is normally EMAIL or SMS.
canHandle(…) returns true if this Handler should be used for the provided
NotificationRequest and ContexInfo. This method allows handlers to be applied only to certain
message types or context information. For example, an application might use different email
providers for different types of messages.
populateNotification(…) is used to update properties on the Notification to prepare it for
for delivery, typically using a MessageBuilder
. For example, the ThymeleafMessageBuilder
locates an appropriate template and builds the messageBody
using the template along with the
data from the Notification.
sendNotification(…) sends the Notification
to a MessageSender
.