Product update announcements
Schedule product update announcement emails
Overview
We can use a scheduled job to run every Monday morning to send out a product announcement email if any new release is detected.
For the sake of simplicity, we’re going to use the public GitHub API to check the latest published release of an open source project to demonstrate how this might work.
Checking a project’s latest release
We can use use the following API endpoint to get the latest release for a project, given the GitHub owner
and repo
names:
For this example, we’re going to use Supabase’s main repository: https://github.com/supabase/supabase
We can see the latest release data here: https://api.github.com/repos/supabase/supabase/releases/latest
We’re going to use the name
and body
markdown field for our email notification, and the release id
to reference the last notification that was sent.
Here’s how we could retrieve that data in TypeScript:
Triggering emails for new releases
Now what we want to do is:
- Fetch the latest release of the repository using the
fetchLatestRelease
function above. - Use the schedule’s
state
to store the ID of last sent release, which we check against the current latest release. - If the current latest release is different from the last sent release, we trigger an email to be sent out to the recipients of our choosing.
Here we handle that in a NextJS API endpoint, using Resend to as our email API:
Note that in the reponse we use the special $set
key to update the state
of the job schedule, so that we can reference the last_sent_release
ID in
future jobs.
The code above will trigger an email of plaintext/markdown, which isn’t ideal. Let’s use react-email and react-markdown to send a prettier email!
Formatting the email HTML
Right now our email is just getting sent in plaintext markdown:
If we want to send some nicer HTML, we can use react-markdown to handle parsing the markdown to React, and react-email to handle rendering a React component as the email.
First, let’s define a React component to render our markdown email:
Now, all we have to do is update our original route to use this component:
Now, when we trigger the email, it should look more like this:
Much better!
Creating the scheduled job
Using our new API endpoint, we can schedule a job to run it every Monday at 10am using a cron expression, using the schedule $state
to reference the last sent release ID: