Automations

Condition

Branch a contact down one of two paths based on event or contact data.

A condition step evaluates a rule against event or contact data and routes the automation down one of two paths: condition met or condition not met. See Using automations for the surrounding workflow.

Common use cases:

  • Plan-based emails — send different content to free vs. paid users.
  • Engagement splits — take different actions based on user activity.
  • Personalization — tailor follow-ups based on event payload values.

How it works

The condition step accepts a type and the corresponding rule fields, plus two outgoing connections — one for each outcome.

import { MailBlastr } from 'mailblastr';

const mb = new MailBlastr('mb_xxxxxxxxx');

const { data, error } = await mb.automations.create({
  "name": "Plan-based welcome",
  "domain": "yourdomain.com",
  "steps": [
    { "key": "start", "type": "trigger", "config": { "event_name": "user.created" } },
    {
      "key": "check_plan",
      "type": "condition",
      "config": { "type": "rule", "field": "event.plan", "operator": "eq", "value": "pro" }
    },
    { "key": "send_pro_email", "type": "send_email", "config": { "template": { "id": "pro-welcome-template-id" } } },
    { "key": "send_free_email", "type": "send_email", "config": { "template": { "id": "free-welcome-template-id" } } }
  ],
  "connections": [
    { "from": "start", "to": "check_plan", "type": "default" },
    { "from": "check_plan", "to": "send_pro_email", "type": "condition_met" },
    { "from": "check_plan", "to": "send_free_email", "type": "condition_not_met" }
  ]
});
console.log({ data, error });

Connection types

A condition step always produces two outgoing connections:

Connection typeDescription
condition_metTaken when the condition evaluates to true.
condition_not_metTaken when the condition evaluates to false.

Operators

A rule condition compares a field against a value using one of the following operators:

OperatorMeaning
eqEquals.
neqNot equals.
gtGreater than.
gteGreater than or equal to.
ltLess than.
lteLess than or equal to.
containsContains a given value.
starts_withStarts with a given value.
ends_withEnds with a given value.
existsField exists (no value required).
is_emptyField is empty (no value required).

Combining rules

Use and or or to combine multiple rules into a single branch. Each entry in rules is itself a condition config — including nested and/or groups.

{
  "key": "check_plan_and_amount",
  "type": "condition",
  "config": {
    "type": "and",
    "rules": [
      { "type": "rule", "field": "event.plan", "operator": "eq", "value": "pro" },
      { "type": "rule", "field": "event.amount", "operator": "gte", "value": 100 }
    ]
  }
}

Configuration

config.typestringrequired

The type of condition node: rule, and, or or.

config.fieldstringrequired

For rule type — the field to evaluate. Must use the event. or contact. namespace prefix (e.g. event.amount, contact.email).

config.operatorstringrequired

For rule type — the comparison operator. See the operators table above.

config.valuestring | number | boolean | nulloptional

For rule type — the value to compare against. Not required for exists and is_empty.

config.rulesobject[]optional

For and / or types — an array of nested condition config objects. Must contain at least one item.