Announcing Courier Automations: Application Logic for Notifications
Tags: notification, saas, automations, announcement
Published: 2022-06-03 21:35:42

We’re excited to announce a powerful new feature for the Courier platform: Courier Automations. Courier Automations is a toolset that includes both an API and a visual builder that allows anyone to easily configure logic for notification workflows. Need to send a reminder to class attendees 10 minutes before the class starts? Need to page an on-call engineer on multiple channels until they respond? These use cases and more can be achieved quickly and easily with Automations. 

## Why we built Automations
As developers, notifications are the primary way that the applications we build communicate with our end-users and the use cases vary widely. Some use cases are very straightforward and simply require that a single message goes to a single user once. Many notifications however require more sophisticated orchestration in order to deliver the desired user experience. Most developers today end up building a separate service to manage this logic. This results in additional infrastructure and development overhead and often in a less than ideal end-user experience. 

We built Automations so that developers can deliver the ideal notification experience without needing to build and maintain yet another service.

## What are product and engineering teams doing with Courier Automations today?

While today marks the official release of Automations, many of our customers are already using Automation to power key parts of their product experience.

The engineering team at [LaunchDarkly](https://launchdarkly.com/), a feature management platform, uses Automations to define the logic for notifications associated with approvals for their customers' feature releases. Any time approval is requested or granted, an Automation is triggered to ensure all the relevant stakeholders are alerted. You can read more about their use case here.

[Officevibe](https://officevibe.com/), which is an employee experience platform, regularly sends out Slack notifications on behalf of their customers asking employees to complete a brief survey. Their engineering team utilizes the Automations API to create lists of users for whom the Slack survey could not be delivered and send them an email survey instead. 

For [Yoga International](https://yogainternational.com/), an online Yoga platform, it's essential that they deliver a seamless experience to their customers from the time they register for a live class through to the start of class. Their engineering team utilizes the Automations API to send timely reminders to class attendees for each live class that happens on their platform.

## “Meetings Reminder”
Let's build a meetings reminder that sends an email reminder 10 minutes before the meeting and a link to the meeting notes two hours after the meeting.

**Design the Messages:**
1. Log into [Courier](https://app.courier.com/) and navigate to the [Notifications Designer](https://app.courier.com/designer/notifications)
2. Design an email reminder that will  be sent 10 minutes before the meeting with the Gmail provider (or any email provider of your choice)
![announcing-courier-automations-1](//images.ctfassets.net/z7iqk1q8njt4/2di1jnFJgbxPu9FRtn1xDg/edd5e62f03fda896df4139b1a1868f2d/announcing-courier-automations-1.png)
3. Access the template ID in the settings of that notification and save it for future reference
4. Design an SMS reminder that will be sent two hours after the meeting with the Twilio provider (or any email provider of your choice)
![announcing-courier-automations-2](//images.ctfassets.net/z7iqk1q8njt4/5T0R822GmEl85UJjpxTT8z/32a31f01a4533dceac58da99e62e7f87/announcing-courier-automations-2.png)
5. Access the template ID in the settings of that notification and save it for future reference

### How To Create an Automation Using the API (Node.js Example)

1. Within your Node.js app, install [node-fetch](https://www.npmjs.com/package/node-fetch)
	`npm install node-fetch`
2. Navigate to the [Automations API Reference](https://www.courier.com/docs/reference/automation/invoke/) and copy the starter code
3. Add an `automations` object with an array of objects called `steps`

```json
"automation": {
      "steps": [
        {
          "action": "send",
          "template": "template_id",
        }
      ]
    },
```

[Automations API Reference](https://www.courier.com/docs/reference/automation/invoke/)

[Automations Docs](https://www.courier.com/docs/guides/tutorials/how-to-automate-message-sequences/)
4. For this example, we will need three steps: send, delay, and another send. The first send step will send the 10 minute reminder. The delay step will wait for two hours after the meeting. The third step will send an SMS with a link to the meeting notes.

```json
"automation": {
    "steps": [
      {
        "action": "send",
        "template": "template_id_1"
      },
      {
        "action": "delay",
        "duration": "130 minutes"
      },
      {
        "action": "send",
        "template": "template_id_2"
      }
    ]
  },
```

5. Update `template_id_1` with the notification template from Step 3 of “Design the Message” and update `template_id_2` with the notification template from Step 5 of “Design the Message”
6. Update the `brand` and `recipient` attributes with your preferred [brand](https://app.courier.com/designer/brands) and [recipient](https://app.courier.com/users) IDs
7. If your steps reference any Notification Templates, update the ID `template` attribute
8. Run your code to trigger the Automation

```js
// Dependencies to install:
// $ npm install node-fetch --save

const fetch = require('node-fetch');

const options = {
  method: 'POST',
  headers: {
    Accept: 'application/json',
    'Content-Type': 'application/json',
    Authorization: 'Bearer replace-token'
  },
  body: JSON.stringify({
    "automation": {
      "steps": [
        {
          "action": "send",
          "template": "template_id_1"
        },
        {
          "action": "delay",
          "duration": "130 minutes"
        },
        {
          "action": "send",
          "template": "template_id_2"
        }
      ]
    },
    "brand": "W50NC77P524K14M5300PGPEK4JMJ",
    "template": "EXAMPLE_NOTIFICATION",
    "recipient": "8ec8c99a-c5f7-455b-9f60-8222b8a27056",
    "data": {
      "name": "Jane Doe",
      "age": 27
    },
    "profile": {
      "phone_number": "2025550125",
      "email": "hello@example.com"
    }
  })
};

fetch('https://api.courier.com/automations/invoke', options)
  .then(response => response.json())
  .then(response => console.log(response))
  .catch(err => console.error(err));
```

9. Check the [Datalog](https://app.courier.com/logs/automations) for delivery status and error messages

### How To Create An Automation Using the Studio
This example demonstrates integrating an API V2 notification send call (Step 5 of "Design the Message").

1. Navigate to the [Automations](http://app.courier.com/automations) page
2. Create an Automation Template from scratch
![announcing-courier-automations-3](//images.ctfassets.net/z7iqk1q8njt4/RjqcqLCVNS9lfXujVjfYi/53e5ac9daa1c3bd6127cd12d31240d98/announcing-courier-automations-3.png)
3. Add a send step and select the “10 minute reminder” for the Notification
![announcing-courier-automations-4](//images.ctfassets.net/z7iqk1q8njt4/376Kg67N5NuoSnRFYkVMD2/d215697c258a3f184426eae7a0acc2ec/announcing-courier-automations-4.png)
4. Add a delay step and update the length to 130 minutes
5. Switch over to code mode (top right, under the the “Publish Changes” button) and add an API V2 notification send call for the SMS with a link to the meeting notes

```json
{
      "action": "send",
      "message": {
        "to": {
      		"email": "example@email.com"
    	},
    	"content": {
    		"title": "Meeting Notes",
    		"body": "Link to meeting notes: ..."
    	}
      }
    }
```

![announcing-courier-automations-5](//images.ctfassets.net/z7iqk1q8njt4/5tHxpIlEfnpIxdYADaM9mk/cda00d734408dde76ef31a4ada77765e/announcing-courier-automations-5.png)
*This step can be done within the designer by following Step 3*

6. Select a trigger for the Automation (if no trigger is selected, the Automation can be triggered manually with a curl command)
7. Publish changes to save your Automation
8. Create a Test Event to test your Automation

```json
{
  "data": {},
  "profile": {
  	"email": "example@email.com",
	“name”: “Your Name”
  }
}
```

![announcing-courier-automations-6](//images.ctfassets.net/z7iqk1q8njt4/1wvA9W2yUDxkEZj6os4yNA/ace96c64264543efaa8a78099cc9b241/announcing-courier-automations-6.png)
9. Invoke your Automation in the Designer or copy the starter code and run it in a terminal

## Getting Started
[Sign up for a free Courier account](https://app.courier.com/signup) to get started with Automations. Courier’s Free Tier includes Automations and up to 10,000 notifications per month.