Trigger An Email After 3 Days of Cold Weather

A workflow that triggers an email about a tropical vacation after 3 days of cold weather. It's useful for an agency who wants to trigger notification based on data from external API and time factors.
  • Call a weather API to get the temperature of the current day during a specific period (ie. number of days)
  • If the temperature is less than 40°F for three days in a row, then send an email to users using gmail.
  • If not, then keep checking everyday until the end of the time period
  • If during the time period, the temperature hasn't dropped below 40°F for 3 days, then send a different promotional email.

Flowchart of the workflow

This flowchart shows a visual representation of the workflow tasks.

flowchart workflow

Workflow Code

View the Github Project . View all of the files, fork the project and deploy to Heroku in a few clicks.

This workflow is the code that orchestrates tasks (through the Zenaton workflow engine) and executes them on your servers. Tasks will be dispatched as soon as three days of cold weather occurs.

const { workflow, duration } = require(‘zenaton’)

// Check the temperature of a given city every day for n days.
// When the temperature drops below minTemp for minRep then send a promotional email via Maichimp
// to visit a warm weather destination. Otherwise send a regular email campaign.
module.exports = workflow('TemperatureCampaignWorkflow', {
 *handle(days, minTemp, minRep, city, emailRecipients) {
   // You can get your connectors id here:
   const openweathermap = this.connector('openweathermap', 'your-connector-id')
   const mailchimp = this.connector('mailchimp', 'your-connector-id')
   let repCount = 0
   do {
     //Check the temperature of Paris via openweathermap API.
     response = yield openweathermap.get(`/weather?q=${city}&units=imperial`)
     //If the temperature is under minTemp degrees (42 degrees fahrenheit) for at least minRep(3 days),
     if (response.main.temp < minTemp) {
     } else {
       repCount = 0
     //wait one day
     yield this.wait.for(duration.days(1));
   } while (repCount < minRep && days > 0)
   //trigger an email campaign on mailchimp based on the weather.
   if (repCount === minRep) {
   } else {