route.js
route.js
is configuration of JavaScript logic for routing the event to trigger.
With input
variable, user can create their own logic for routing.
result should be a trigger name, it will execute trigger.js
of trigger.
Example route.js
try {
// Response for validation token when creating subscription
if (input.notification.params.query.validationToken) {
return {
}
} else {
// Response for notification
const automationId = input.notification.params.body.value[0].clientState
const chnageType = input.notification.params.body.value[0].changeType
if (chnageType === "created") {
return {
target: automationId,
trigger: "email.received"
}
} else if (chnageType === "updated") {
// email.sent and email.updated
return {
target: automationId,
}
} else if (chnageType === "deleted") {
return {
target: automationId,
trigger: "email.deleted"
}
}
}
} catch (error) {
throw error;
}
Helpful?