Expression

🎯 Purpose

An Expression is used to filter clients participating in a campaign. It is a script written in JavaScript or Python that evaluates a specific client's data and returns true or false. Only clients for whom the result is true will be included in the campaign execution.


βš™οΈ Using the JavaScript/Python Engine

The timveroOS platform supports script execution in both JavaScript and Python via the ScriptManager component.

The CampaignExecutionService compiles the expression with:

Script script = scriptManager.compile(expression);

And evaluates it for each client with:

Object evaluationResult = script.eval(Map.of("client", client));

πŸ’‘ The script runs in a sandboxed environment with no access to unsafe resources. Compilation or runtime errors are wrapped in a ScriptException and logged.


πŸ” Security

Scripts are executed with strict limitations:

  • Restricted classes

  • Execution timeouts

  • No external system access

Any error (e.g., NullPointerException, syntax error) is captured in an ExceptionEntity and shown in the UI as EXCEPTION_OCCURRED.


πŸ§ͺ Expression Example

client.age > 25 && client.income > 3000 && client.country == "UK"

This expression selects clients who are:

  • Older than 25

  • Have an income over 3000

  • Live in the United Kingdom


πŸ“Œ Code Usage Example

private Optional<Client> evaluateClient(Script script, UUID clientId) throws ScriptException {
    Client client = clientRepository.getReferenceById(clientId);
    Object result = script.eval(Map.of("client", client));
    return Boolean.TRUE.equals(result) ? Optional.of(client) : Optional.empty();
}

Last updated

Was this helpful?