Triggering Events

Using Cloud you can trigger events just like you would using the Design app

(function(payload) {
  trigger('EVENT_NAME')
})

This allows you to move static content away from your code.

(function(payload) {

  // Get today in CEST
  const today = moment(new Date()).tz('Europe/Amsterdam')

  // Office opens at 8am
  const hoursStart = 8

  // Office closes at 5.30pm
  const hoursEnd = 17.5

  const dayOfWeek = today.day()
  const currentHour = today.hour()
  const isWorkday = (dayOfWeek <= 5)
  const isOfficeHours = (currentHour >= hoursStart && currentHour < hoursEnd)

  toolbelt.takeover()

  if(isWorkday && isOfficeHours) {
  	// We are at work
  	trigger('TAKEOVER_OFFICE_HOURS')
  } else {
    trigger('TAKEOVER_OUT_OF_OFFICE')
  }
})

The example above is a piece of Cloud Code that would trigger 2 different flows depending on the current time.