-
Notifications
You must be signed in to change notification settings - Fork 129
Notifications
By configuring a notification, cenit is instructed to execute some logic to notify some external endpoint when an event take place. It’s possible to configure notification of the following types
- Web-Hook, who’s logic is to make custom HTTP requests.
- Emails, who’s logic is to send an email.
In both cases a notification is configured to listen for an event in an specific data type, so the data type is first selected and then an event for such data type. Multiple events can be associated with the same notification.
For Web-Hook notifications an URL and an HTTP verb (method) should be provided to make the request, the content of the request is configured using a template. The event triggers the web-hook notification and the template is applied to the event source record, and the result is sent to the endpoint via HTTP protocol using the configured URL and verb.
For Email notifications, in addition to the template/transformation and email channel is required, which is used to send emails. An email channel can be an email flow or an SMTP account. The first uses a common cenit flow to send the email, the second uses an SMTP configuration and credentials. Multiple accounts can be configured for the same SMTP server and for this reason the configuration have been separated into SMTP providers (say Gmail) and SMTP account which actually contains the credentials to use the email service.
Now to send an email notification cenit should be configured to transform the source event record into a message. At cenit.io the data type for managing messages is Message, from the name space MIME. Local instances of cenit should configure a data type for that purpose by editing the configuration and the Administration menu. It can be any data type, the MIME | Message can be imported from cenit.io by pulling the remote shared collection MIME.
To transform the source event record, say for example an order that is created and so a notification must be sent to the custumer, there are two choices, configure a Template or a Conversion. A template should transform the source record into a format suitable to be parsed by cenit into a the email data type. For example a JSON Liquid template to transform an order into a message can have the following code, assuming the source data type for orders have the properties confirmation_email, order_number and custumer_name.
{
“to”: “{{confirmation_email}}”,
“subject”: “Order {{order_number}} confirmation.”,
“body”: “Dear {{costumer_name}} your order {{order_number}} have been successfully created.”
}
A better approach is to configure the email notification using a Converter transformation to transform the source record into a message. There can be used any of the cenit converter types, perhaps the Mapping Converter is the more user friendly to configure a mapping between the properties of the source data type and the ones of the message when using the cenit UI. Just type {{
and the mapping field component will suggest the source property to auto-complete the map.
Finally, take into account that a notification should be active to be executed, so don’t forget to check the active field configuration, or uncheck it, to prevent the notification to be executed.