Conditions

Use conditional logic to control the flow and display messages only if the specified conditions are met.

Here is an example:

{
  "type": "question",
  "entity": "sum",
  "entity-type": "Number",
  "messages": [
    "How much is 2 + 2?"
  ]
},
{
  "conditions": [
    "{{$eq sum 4}}"
  ],
  "type": "message",
  "messages": [
    "✅ Correct."
  ]
},
{
  "conditions": [
    "{{$ne sum 4}}"
  ],
  "type": "message",
  "messages": [
    "❌ Incorrect."
  ]
}

Check all of the supported conditional expressions you can use.

Entity presence

You can check if an entity is defined in the bot memory using the $has formatter.

    <!-- '{ "FirstName": "John", "LastName": "Smith" }' -->
    {{$json user}}

    <!-- true -->
    {{$has user.FirstName}}

    <!-- false -->
    {{$has user.MiddleName}}

You can use the $in formatter to check if an entity value is present in an array.

    {{$in date datesArray}}

Comparisons

You can evaluate comparisons using some of the comparison formatters:

  • $eq - equals
  • $gt - greater than
  • $gte - greater or equal
  • $lt - less than
  • $lte - less or equal
  • $ne - not equal
    <!-- 5 -->
    {{grade}}

    <!-- true -->
    {{$gt grade 3}}

Boolean logic

You can evaluate boolean logic using some of the boolean formatters:

  • $or
  • $and
  • $not
    <!-- 4 -->
    {{grade}}

    <!-- true -->
    {{$and ($gt grade 3) ($lt grade 5)}}