Skip to content

Working with Rules

Alexis Smirnov edited this page Mar 8, 2020 · 3 revisions

The answers users provide are classified into one or more classes using a set of rules. Defining rules is handled by json-rules-engine.

Definitions

  • Facts are the values (answers) collected through the chat
  • Rules are the evaluation of those facts
  • Results are generated from the rules being applied to those facts

Adding rules

All rules are in rules/global.json

For example:

...
  {
    "conditions": {
      "all": [
        {
          "fact": "askForLocationOptions",
          "operator": "equal",
          "value": "AB"
        }
      ]
    },
    "event": {
      "type": "askForLocationOptions",
      "params": {
        "classes": ["ca-ab"]
      }
    }
  }
...

This rule states that if a question askForLocationOptions has the answer AB then we'll append the class ca-ab to the classes for this user.

On Step

They can also be defined on a step directly under metadata. Step-defined rules will only be applied if that step was rendered.

e.g.

steps={[
  {
    id: '1',
    message: 'Pick a number',
    trigger: '2',
    metadata: {
      rule: {
        "conditions":{...},
        "event":{...}
      }
    }
  },
  ...
]}
Clone this wiki locally