Skip to content
This repository has been archived by the owner on Dec 8, 2017. It is now read-only.

Notifications

Roger Steve Ruiz edited this page Nov 27, 2015 · 6 revisions

The notification process works like this:

  1. Create a notification model with an action and a model. The action is a string name for the notification, and the model is a model associated with the notification, for instance, the user for a user welcome email notification. By convention, I'm naming actions as model.method.name, like user.create.welcome.
  2. When a new notification is created, it triggers a notification email, which builds the data object for the email and constructs the email header and body from templates compiled with the data object.
  3. Triggering a notification automatically renders and sends it; trigger, render and send are all model methods now instead of a separate service.

Adding / editing an email template is much easier. Email templates now consist of two files in a folder named after the action:

api/notifications/
  |- user.create.welcome/
    |- notification.js
    |- template.html
  |- layout.html
  • notification.js exports template strings for header fields to, cc, bcc, and subject as well as a data function that takes the notification's associated model and a callback and returns a data object used to build the templates
  • template.html is an html underscore template file for the body
  • layout.html is a global layout template that all notification body content gets rendered into before sending

We rely on our our mailing API to inline CSS and convert HTML templates to plain-text.