Variants is a workflow component that empowers users to create multiple versions of a given workflow step.

You can use variants to ensure that only specific versions of your workflow step (e.g Email) are sent to subscribers. These variants are linked to specific conditions. No variant can exist without a condition.

Variants are an integral component of our multi-tenancy feature.

Steps to create Variants

In this case, we’ll use a workflow Email step. Let’s create multiple variants for this step.

  1. Create an email step in your workflow.

Email step in workflow

  1. Add a variant to the step as shown below.

Add variant to workflow step

  1. A variant must have conditions set. Add a condition or multiple conditions.

Add conditions

In this case, we added a condition (as shown below) to check if the tenant identifier passed at the point of trigger is equal to edenlife. This is now a multi-tenant variant!

Apply conditions to set it successfully.

Add conditions for the variant

The variant has been created. Click on the Update button.

Update the variant

  1. Head over to the email step again. You will see two variants: the root variant & v1 variant. The v1 variant is the one where you set the tenant condition while the root variant is the default version of the email step without a condition.

Root & v1 variants

  1. You can add different content to the two variants.

Root variant

v1 variant

During the notification sending phase, Novu’s logic will determine the appropriate variant based on the contextual information that was passed with the trigger event and the conditions applied to the variants.

In this case, if a tenant identifier with the value of edenlife was passed with the trigger event, then Novu will select the v1 variant and send to subscribers.

On the other hand, if the tenant identifier has a different value or was not passed with the trigger event, then Novu will select the root variant and send to subscribers.

  import { Novu } from '@novu/node';

  const novu = new Novu("<NOVU_API_KEY>");

  await novu.trigger('<WORKFLOW_TRIGGER_IDENTIFIER>',
    {
      to: {
        subscriberId: '<UNIQUE_SUBSCRIBER_IDENTIFIER>',
      },
      payload: {
        name: "Hello World",
      },
      tenant: "edenlife"
    }
  );

Variant Conditions

There are so many use cases for variants. It’s not limited to multi-tenancy.

You can set conditions based on the following data:

  • Subscriber
  • Payload
  • Webhook
  • Is online
  • Last time was online

Sample Use Cases

  1. If you’re looking to send a different type of email based on whether a subscriber is online, then variants are the right choice.

  2. If you want to send different types of email to subscribers based on the specific type of payload or subscriber data passed with the trigger event, variants are a good choice!