Auto Response Trigger (Advanced Trigger)

Last Updated: 28/11/2024     Tags: trigger, triggers, advanced, js, javascript
  • Switch Version
  • V5
  • V4

A sequence of multiple emails can be scheduled from a single trigger.

st=>start: Event e=>end: End op1=>operation: Send Trigger #1 op2=>operation: Send Trigger #2 op3=>operation: Send Trigger #3 op4=>operation: Send Trigger #4 st(right)->op1(right)->op2(right)->op3(right)->op4(right)->e

JS Code

The following code sends an initial welcome email, then schedules one email per week for the next 4 weeks:

var tm = require('tm'),
    activityIds = [1, 2, 3, 4, 5],  // Replace with the email sequence IDs
    msPerWeek = 7 * 24 * 60 * 60 * 1000;  // Milliseconds per week

exports.handler = function (event){
    tm.send(activityIds[0], event.subscriber.id);
    tm.send(activityIds[1], event.subscriber.id,
            new Date((new Date()).valueOf() + msPerWeek));
    tm.send(activityIds[2], event.subscriber.id,
            new Date((new Date()).valueOf() + msPerWeek * 2));
    tm.send(activityIds[3], event.subscriber.id,
            new Date((new Date()).valueOf() + msPerWeek * 3));
    tm.send(activityIds[4], event.subscriber.id,
            new Date((new Date()).valueOf() + msPerWeek * 4));
}

Reference

For more information about advanced triggers, see the Advanced Trigger Reference.