Register New Notification Type¶
This guide describes the basic steps to define a new e-mail notification type, including its registration in the notification registry.
Prerequisites¶
Define custom email notification type¶
Create a notification and give it a name, for example, SampleEmailNotification
, basing it on the EmailNotification
class (as opposed to another standard class, SmsNotification
):
public class SampleEmailNotification : EmailNotification
{
public SampleEmailNotification() : base(nameof(SampleEmailNotification)) {}
public string Greeting { get; set; }
}
Registration in notification registry¶
Register your SampleEmailNotification
in the notification registry:
Notes to the code:
Line 4: Getting the instance of INotificationRegistrar
type that stores all known notification types used in the system.
Line 5: Registering SampleEmailNotification
and setting a default template by running the WithTemplates
extension method. In Template.Subject
, we use the {greeting}
liquid expression that will be replaced with the Greeting
property value of the SampleEmailNotification
class instance after rendering.
Localize notifications¶
Virto Platform Manager supports localization resources for notification types. This is achieved by adding a JSON object to the notificationTypes
section, the key having the same name as the notification type:
"notificationTypes": {
...
"SampleEmailNotification": {
"displayName": "Sample email notification",
"description": "Some sample email description"
},
...
}
Send notifications¶
To send a notification from your code, use two interfaces: INotificationSearchService
and INotificationSender
.
You can send a notification based on this code sample as follows:
|
Notes to the code:
Line 15: Constructing a new instance of the SampleEmailNotification
type by calling the INotificationSearchService.GetNotificationAsync<>
extension method.
Lines 16 to 19: Populating the required email notification properties, such as From
and To
, and setting a value for our custom Greeting
property; this value will be eventually interpolated in the email subject, for example, Hi { greeting } → Hi John.