Notifications - HelpRefugees/project-flamingo GitHub Wiki

Currently there are two kinds of notification tasks used by Project Flamingo:

  • "report-due": triggered by yarn send-due-emails (see scripts/send-due-emails.js); and

  • "reset-password": triggered by a POST request to /api/password/forgot, if there is a user with the supplied email address (see server/routes/password.js).

These notifications are both dealt with in the same way, by sending a POST request to the endpoint specified by the EMAIL_WEBHOOK environment variable. The logic for this is in scripts/email-sender.js if you need to override it.

Webhook

The webhook should accept a JSON payload containing:

  • "task", the string name of the task (see above);
  • "recipients", an array of string email addresses to dispatch to; and
  • additional arbitrary task-specific keys.

For example, to dispatch a password reset email to "[email protected]", the tool could POST the following body:

{
  "task": "reset-password",
  "recipients": ["[email protected]"],
  "resetToken": "5faffbf0ac24d608d9dd28152d4c954a"
}

Zapier

Currently, we are using Zapier to provide the webhook and handle dispatch. In the acceptance environment we send the raw JSON body to a Slack channel for testing purposes. In production we are using the Paths feature to handle the resulting action based on the "task" key in the payload, sending appropriate emails based on the templates in script/templates.

Note that if you add new keys to the payload you need to run additional "tests" (go to the trigger section and click "Test This Step", then "Get More Samples") for those keys to show up and be usable in your actions.