joystick icon indicating copy to clipboard operation
joystick copied to clipboard

Add email.sequence() method

Open rglover opened this issue 2 years ago • 0 comments

This is a wild idea but really helpful. Sequence emails are extremely common for SaaS apps. Idea would be to have a way to define sequences at the app level and then trigger them via the global process.emailSequences.<name>.start('[email protected]').

Behind the scenes, Joystick would automatically queue up sends relative to the secondsAfterLastEmail number you provide. Sends would be tracked in a database flagged as emailSequences: true in your config file. The database could track lastSentAt and automatically determine if an email should be sent. If a server goes down, could set it up to send emails that should have gone out during downtime automatically. For the emails, you could pass input which could be handled via an optional props function (this could also receive a static object) that could dynamical retrieve props at send time.

For the first email, secondsAfterLastEmail would be derived from the startedAt value set when calling .start().

import node, { email } from "@joystick.js/node";
import api from "./api";

node.app({
  api,
  emailSequences: {
    onboarding: [{
      secondsAfterLastEmail: 300,
      template: 'sequences/onboarding/welcome',
      props: () => {
        return {
          dynamic: 'prop',
        };
      },
    }, {
      secondsAfterLastEmail: 300,
      template: 'sequences/onboarding/getting-started',
      props: () => {
        return {
          dynamic: 'prop',
        };
      },
    }],
  },
  routes: {
    "/": (req, res) => {
      res.render("ui/pages/index/index.js", {
        layout: "ui/layouts/app/index.js",
      });
    },
    "*": (req, res) => {
      res.render("ui/pages/error/index.js", {
        layout: "ui/layouts/app/index.js",
        props: {
          statusCode: 404,
        },
      });
    },
  },
});

rglover avatar Sep 06 '23 04:09 rglover