This workflow is the code that orchestrates tasks (through the Zenaton workflow engine) and executes them on your servers. Tasks inside the workflow are not detailed here.
const { workflow, duration } = require("zenaton");
module.exports = workflow("ProductReturnWorkflow", {
*handle(parcelReturn) {
/* Connect to Sendgrid with Zenaton API connector */
const sendgrid = this.connector('sendgrid', 'your-connector-id');
this.parcelReturn = parcelReturn;
const email = this.parcelReturn.email;
/* Run task to create the parcel return inside application */
yield this.run.task("CreateReturnParcel", this.parcelReturn);
/* Get parcel return data from database */
const status = yield this.run.task("GetParcelData", this.parcelReturn);
/* If the reason for return is status 1 */
if (status === "status_1") {
/* Send a email template 1 with Sendgrid */
sendgrid.post('/mail/send', {body: {"template_id": "template_1", ...}})
/* Escalate the issue to an operator with Zendesk */
this.run.task("AssignSupportOperatorZendesk");
/* If the reason for return is status 2 */
} else if (status === "status_2") {
/* Send a email template 2 with Sendgrid */
sendgrid.post('/mail/send', {body: {"template_id": "template_2", ...}})
/* Send a request for to the user a review with Trustpilot API */
this.run.task("AskReviewTrustPilot");
/* If the reason for return is the last status */
} else {
sendgrid.post('/mail/send', {body: {"template_id": "template_x", ...}})
}
/* Wait for the parcel to ship event until 3 days */
const shipped = yield this.wait.event("Shipped").for(duration.days(3));
/* If the user hasn't sent the product in 3 days */
if (!shipped) {
/* Another reminder workflow is launched */
yield this.run.task("EmailReminderWorkflow");
}
}
});
A workflow instance is launched when a user requests a return.
Real-world Examples
Start building workflows
Sign-up and run a sample project Learn more