Platform
Docs
Solutions
ContactLog In

Start Routing Notifications Today!

Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.

Sign-up

the-three-things-to-never-build-in-your-app-header
INTEGRATIONSENGINEERING

The Three Things to Never Build In Your App: Authentication, Notifications, and Payments

Tejas Kumthekar

May 13, 2021

Back in early 2018, I embarked on a side gig with a few partners - the idea was to make ridesharing socially engaging and fun. We made a ton of mistakes and never really got the product off the launchpad, however in retrospect, the biggest mistakes we made were wasting precious time in writing code for authentication and authorization as well as user notifications. We learned to focus on customer value the hard way.

Every startup should consider the trade-offs of buying vs building non-differentiated features like authentication, notifications, payments etc. Companies like Auth0 (authentication and authorization platform), Courier (one API to design and deliver notifications across multiple channels), and Stripe (payments infrastructure for the internet) have solved these problems so you, the entrepreneur or developer, can stay laser-focused on what your users truly want out of your product.

Whether you are working on a side gig like me or starting a company, shipping an MVP as quickly as possible helps you get feedback much earlier in the product development cycle. Outsourcing authentication, notifications, and payments tremendously helps in rolling your MVP out the door. The project I mentioned above took months to reach the MVP stage and outsourcing the non-core features could have had a great impact on shortening that time frame.

In this post, we shall focus on a pretty common use case that suits almost every product you will ever build. A user signs up for your product, you save the user details, and send them a welcome message. We will be using Auth0’s post-user registration hook and Courier’s automations feature to build this use case fairly quickly. Let’s dive right in!

With a single “send” API invocation, you can use Courier to reach your customers across one or more channels (email, text, push, or a direct message). We learned through talking to our customers that more often than not, they need something more powerful than just a single “send” action. They need workflows that do multiple actions with a single invocation, like making a single API call to send an email to their users and wait for a desired period of time (inducing a delay) and thereafter send a follow-up email. Another example of a workflow we've heard quite a lot is scheduled notifications, like sending product updates every week. The Courier Automations API gives you the ability to build such workflows and quite literally “automate” your notifications. We will see it in action soon :)

Configuring the Courier side of things

Let's start by creating a free account on Courier, which lets you send up to 10,000 free notifications every month. For the use case we are tackling in this blog post, we will be leveraging Courier’s Automations API. With a single API call, you’ll be able to create a new user profile inside Courier followed by a welcome message to send to this newly created user. The Automations Guide has a detailed walkthrough of all the cool features unlocked via Courier’s Automations API. Today, we will be invoking an automation that has two steps - update-profile and send.

Step 1: update-profile

This step essentially takes any profile JSON object with a unique ID (called recipient ID) and saves it inside Courier. It stays as a permanent record inside Courier that you can further use to send notifications, add it to a list of users/profiles, customize preferences such as opt-in/opt-out, and so on. In our use case, this would originate from Auth0. Here’s how it would look:

1
{
2
"action": "update-profile",
3
"recipient_id": "<RECIPIENT_ID>",
4
"profile": {
5
// User properties from Auth0
6
// plus any more properties you want to attach to the user
7
},
8
"merge": "none"
9
}

&lt;RECIPIENT_ID&gt; =  A unique ID that you can use to identify your user.

``

Step 2: send

This step sends a welcome email to the user. We will be sending users an email using Sendgrid as the downstream email provider. This Setup Email using SendGrid guide walks you through sending an email notification using Courier and SendGrid. Once you have created a notification template (with email as the channel using SendGrid), you can construct a send step that looks like this:

1
{
2
"action": "send",
3
"profile": {
4
"email": "foo@bar.com"
5
},
6
"recipient": "<RECIPIENT_ID>",
7
"template": "<TEMPLATE_ID>"
8
}

<RECIPIENT_ID> = User ID you are sending the notification to (same as step 1)

<TEMPLATE_ID> = ID of the notification template you just created for welcoming the new user.

Final Payload

Here’s how the payload to automations/invoke endpoint will look:

1
{
2
"automation":{
3
"steps":[
4
{
5
"action":"update-profile",
6
"recipient_id":"unique-foo",
7
"profile":{
8
"email":"foo@bar.com",
9
"first_name":"Foo",
10
"last_name":"Bar"
11
},
12
"merge":"none"
13
},
14
{
15
"action":"send",
16
"profile":{
17
"email":"foo@bar.com"
18
},
19
"template":"AAZRHC4TDAMEHKGJHDAA9199WMVH",
20
"recipient":"unique-foo"
21
}
22
]
23
}
24
}

Configuring the Auth0 side of things

This post assumes you have a basic understanding of Auth0 and have set up an application in Auth0 before, but if not, follow the Auth0 Getting Started guide.

Let's take a step back and imagine how things would look if there was no integration between Auth0 and Courier. Every time you would have a new user signed up with Auth0, you would have to explicitly invoke Courier to create their profile and send them a welcome message. This would require writing more code in your application, deploying it reliably and maintaining it as your application scales. Having Auth0 and Courier integrated out of the box gives you great leverage in the form of speed and agility to move fast - without having to maintain a single line of code in your infrastructure.

We want Auth0 + Courier to work together automatically - like magic. Once a new user registers for the product, we want to trigger Courier’s Invoke Automation API - this is where Auth0 Post-User Registration comes into picture. Here’s the code that lives behind Auth0 hook and uses the Courier Node.js SDK to invoke the automation dynamically based on the user obtained via Auth0 registration.

1
module.exports = async function (user, context, cb) {
2
const { CourierClient } = require("@trycourier/courier");
3
const courier = CourierClient({ authorizationToken: context.webtask.secrets.COURIER_AUTH_TOKEN });
4
5
await courier.automations.invokeAdHocAutomation({
6
automation: {
7
steps: [
8
{
9
action: "update-profile",
10
recipient_id: user.id,
11
profile: {
12
email: user.email,
13
username: user.username,
14
phoneNumber: user.phoneNumber
15
},
16
merge: "none"
17
},
18
{
19
action: "send",
20
profile:{
21
email: user.email
22
},
23
template: "AAZRHC4TDAMEHKGJHDAA9199WMVH",
24
recipient: user.id
25
}
26
]
27
}
28
});
29
cb();
30
};

This saves the user profile to Courier followed by sending the welcome email you configured in the template.

The profiles can be viewed in Courier UI under Data Recipients tab:

View Profiles in Courier UI

Next, the welcome email is sent to the user - it looks just like how you configured it to look in Courier. Just to give an example of how a notification could look:

Welcome to Courier Email

Feel the Magic Automation?

We just saw how Auth0 + Courier can help you automagically build user onboarding flow without having to maintain any code in your own system, and as we all know, the best code is no code that allows us to focus our energies where they are most needed.

Of course, Courier Integrates with more than just Auth0. Just like we sent an email using Sendgrid in this blog post, you can use any of these channels - email, SMS, push, direct messaging, etc. with providers like Mailgun, Twilio, and Slack with just a single API to power your notification workflows. Sign up for a free Courier account. You build the next big thing and let us handle the notifications for you. 🚀

Additional References -

Courier Docs

Auth0 docs

Courier Node.js SDK

Start Routing Notifications Today!

Courier is a notification service that centralizes all of your templates and messaging channels in one place which increases visibility and reduces engineering time.

Sign-up

More from Integrations

datadog-notification-observability-thumbnail
PRODUCT NEWSINTEGRATIONS

New Datadog integration for Courier notification logs and metrics

The ability to unify all notification metrics and logs across channels and providers into an easy-to-use dashboard is a core advantage of Courier’s notification infrastructure. However, with product notifications so critical to the entire application experience, it’s important to connect that data back to central cloud observability platforms that look across the entire stack. This gives platform engineering teams a complete understanding of application health and lets them quickly troubleshoot even the most complex issues. Today, we’re incredibly excited to announce our first observability integration with Datadog. [Datadog](https://www.datadoghq.com/) is a tool for collecting metrics and other data from applications and viewing them in a centralized place. Datadog’s dashboards and monitoring tools build a more accurate picture of the health of your application and how it changes over time. Our integration with Datadog is easy to spin up when you use our “dashboard starter kit.” This consists of some pre-configured JSON to set up a simple dashboard in Datadog for your Courier data. Our Datadog integration is currently only available on Courier’s Business plan, much like our other production-focused features such as [template analytics](https://www.courier.com/docs/platform/logging/analytics/), [Okta integration for SSO](https://www.courier.com/docs/platform/workspaces/okta-integration/), and [advanced user preferences](https://www.courier.com/docs/platform/preferences/preference-center/introduction/).

Robert Fenstermacher

Robert Fenstermacher

April 11, 2023

Rudderstack integration thumbnail
PRODUCT NEWSINTEGRATIONS

New RudderStack integration: Create actionable data insights

Are you looking for a way to gain a clearer picture of your users and use that insight to improve your communication strategies? We've got some great news for you! Today, we're thrilled to announce an integration between Courier and RudderStack, a customer data platform (CDP) that allows businesses to collect, process, and route customer event data across product, marketing, and analytics tools for better decision-making. This integration builds on our recently improved integration with Segment and will further improve your ability to track your users' actions and take advantage of customer data stored in RudderStack to improve the notification experience for your users.

Tejas Kumthekar

Tejas Kumthekar

March 07, 2023

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Build your first notification in minutes

Send up to 10,000 notifications every month, for free.

Get started for free

Email & push notification

Platform

Users

Content

Channels

Sending

Workflows

Preferences

Inbox

Workspaces

Observability

API Status

Changelog

© 2024 Courier. All rights reserved.