line

Product Return

This Workflow optimizes a customer product return process by automating internal processes and interfacing with external services: Chronopost, Sengrid, Zendesk and TrustPilot API. This workflow automates a customer product return by generating and sending information to the customer and then sending status updates and notifications to the customer and internal team when events occur - or trigger other actions if they don't occur.

Visual of Workflow

This flowchart shows a visual representation of the workflow tasks.
line

Workflow Code

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");
    }
  }
});

Workflow Steps

A workflow instance is launched when a user requests a return.

  • Identify the reason for the return
  • Create a parcel return in our internal application
  • Get parcel data and generate a QR code with Chronopost API
  • Check the reason for the return and send an email template via Sendgrid using the right template and attach QR code from chronopost
  • Depending on the reason for the return, trigger specific tasks such as "Assign an Operator" or "Ask for a Review"
  • Wait for up to three days to receive an external event that the user shipped the product
  • If it has been shipped, the workflow is completed
  • If not, an email reminder subworkflow is launched to remind the user to send the parcel and follow up if they do not

Workflow Executions

View the real-time tasks executions of this workflow.
line