﻿
# Condition engine

The Condition engine is a general-purpose framework for defining conditions. Conditions control the visibility or execution of application features, such as [Functions](../functions/function-reference.md), and determine when [Buttons](../functions/buttons.md) appear. They evaluate criteria against real-time application state and can be combined with logical operators to express complex rules.

## Syntax

Conditions are represented as JSON and defined by the [Condition JSON schema](https://schemas.acrobits.net/core/conditions/condition.json).

A condition is a JSON object containing an `"@": "type"` property. The remaining properties depend on the condition type.

The following sections describe all available condition types.

---

### Account key

Checks whether an account-level property matches a specified value.

**Type:** `accountKey`

| Field          | Type                                       | Description                |
|----------------|--------------------------------------------|----------------------------|
| `key`          | String                                     | Account property to check. |
| `matchType`    | `equal`, `startWith`, `endWith`, `contain` | Matching strategy.         |
| `matchPattern` | String                                     | Pattern to match against.  |

```json
{
    "@": "accountKey",
    "key": "crm_enabled",
    "matchType": "equal",
    "matchPattern": "1"
}
```

---

### Scope memory variable

Checks whether a scope memory variable matches a specified value. The applicable scope depends on where the condition is used.

**Type:** `variable`

| Field          | Type                                       | Description                                                                       |
|----------------|--------------------------------------------|-----------------------------------------------------------------------------------|
| `name`         | String                                     | Variable name. Can include a scope prefix (see [Scopes](../functions/scopes.md)). |
| `matchType`    | `equal`, `startWith`, `endWith`, `contain` | Matching strategy.                                                                |
| `matchPattern` | String                                     | Pattern to match against.                                                         |

```json
{
    "@": "variable",
    "name": "sipHeader[myVariableName]",
    "matchType": "equal",
    "matchPattern": "hello"
}
```

---

### Call direction

Matches the direction of the current call.

**Type:** `callDirection`

| Field       | Type                   | Description                  |
|-------------|------------------------|------------------------------|
| `direction` | `incoming`, `outgoing` | The call direction to match. |

```json
{
    "@": "callDirection",
    "direction": "incoming"
}
```

---

### Call state

Checks whether the current call is in one of the specified states.

**Type:** `callState`

| Field    | Type             | Description                                  |
|----------|------------------|----------------------------------------------|
| `states` | Array of strings | List of call states to match (see Call FSM). |

```json
{
    "@": "callState",
    "states": ["incomingRinging", "established"]
}
```

---

### Caller display name

Matches the caller's display name against a pattern.

**Type:** `callerDisplayName`

| Field          | Type                                       | Description        |
|----------------|--------------------------------------------|--------------------|
| `matchType`    | `equal`, `startWith`, `endWith`, `contain` | Matching strategy. |
| `matchPattern` | String                                     | Pattern to match.  |

```json
{
    "@": "callerDisplayName",
    "matchType": "contain",
    "matchPattern": "Support"
}
```

---

### Caller transport URI

Matches the caller's SIP transport URI against a pattern.

**Type:** `callerTransportUri`

| Field          | Type                                       | Description        |
|----------------|--------------------------------------------|--------------------|
| `matchType`    | `equal`, `startWith`, `endWith`, `contain` | Matching strategy. |
| `matchPattern` | String                                     | Pattern to match.  |

```json
{
    "@": "callerTransportUri",
    "matchType": "endWith",
    "matchPattern": "example.com"
}
```

---

### Group size

Checks the number of calls in the current group.

**Type:** `groupSize`

| Field  | Type                             | Default | Description                |
|--------|----------------------------------|---------|----------------------------|
| `size` | Number                           | —       | Number to compare against. |
| `op`   | `==`, `!=`, `>`, `<`, `>=`, `<=` | `>=`    | Comparison operator.       |

```json
{
    "@": "groupSize",
    "size": 2,
    "op": "<"
}
```

---

### Preference key

Matches a preference key's current value against a pattern.

**Type:** `prefKey`

| Field          | Type                                       | Description          |
|----------------|--------------------------------------------|----------------------|
| `key`          | String                                     | Preference key name. |
| `matchType`    | `equal`, `startWith`, `endWith`, `contain` | Matching strategy.   |
| `matchPattern` | String                                     | Pattern to match.    |

```json
{
    "@": "prefKey",
    "key": "allowAutoAnswer",
    "matchType": "equal",
    "matchPattern": "1"
}
```

---

### Version

Checks the application library version against a range.

**Type:** `version`

| Field     | Type   | Description                                               |
|-----------|--------|-----------------------------------------------------------|
| `minimum` | String | Lower version bound (exclusive). Semantic version format. |
| `maximum` | String | Upper version bound (exclusive). Semantic version format. |

```json
{
    "@": "version",
    "minimum": "1.1.1",
    "maximum": "2.0.0"
}
```

---

### Platform

Checks the platform the app is running on.

**Type:** `platform`

| Field      | Type   | Description                                                                         |
|------------|--------|-------------------------------------------------------------------------------------|
| `platform` | String | One of: `Android`, `iOS`, `Windows`, `Mac`, `Linux`, `Desktop`, `Mobile`, `Shared`. |

```json
{
    "@": "platform",
    "platform": "iOS"
}
```

---

### Is conference

Checks whether the current call scope refers to a conference. Returns `true` when the scope represents a call that is part of a conference but does not resolve to a specific call within that conference.

**Type:** `isConference`

No fields.

```json
{
    "@": "isConference"
}
```

---

### Logical operators

#### AND

All listed conditions must evaluate to `true`.

**Type:** `and`

| Field      | Type                | Description            |
|------------|---------------------|------------------------|
| `operands` | Array of conditions | Conditions to combine. |

```json
{
    "@": "and",
    "operands": [
        { "@": "callDirection", "direction": "incoming" },
        { "@": "callState", "states": ["established"] }
    ]
}
```

#### OR

At least one condition must evaluate to `true`.

**Type:** `or`

| Field      | Type                | Description            |
|------------|---------------------|------------------------|
| `operands` | Array of conditions | Conditions to combine. |

```json
{
    "@": "or",
    "operands": [
        { "@": "callerDisplayName", "matchType": "contain", "matchPattern": "Support" },
        { "@": "callerDisplayName", "matchType": "contain", "matchPattern": "Helpdesk" }
    ]
}
```

#### NOT

Negates a condition.

**Type:** `not`

| Field     | Type      | Description              |
|-----------|-----------|--------------------------|
| `operand` | Condition | The condition to negate. |

```json
{
    "@": "not",
    "operand": { "@": "callDirection", "direction": "outgoing" }
}
```

---

### Testing utilities

#### Always true

Always evaluates to `true`. Useful for testing.

**Type:** `alwaysTrue`

```json
{
    "@": "alwaysTrue"
}
```

#### Always false

Always evaluates to `false`. Useful for testing.

**Type:** `alwaysFalse`

```json
{
    "@": "alwaysFalse"
}
```

#### Random

Randomly evaluates to `true` or `false`. Useful for testing. When **Random** is used in a reactive context, `intervalMilliseconds` controls the refresh rate.

**Type:** `random`

| Field                  | Type | Description                                                                                               | Default |
|------------------------|------|-----------------------------------------------------------------------------------------------------------|---------|
| `intervalMilliseconds` | int  | How often the random value changes. If set to `0`, the value does not refresh. *Added in 26.2.*             | 1000    |

```json
{
    "@": "random",
    "intervalMilliseconds": 2134
}
```

---

### Internal conditions

#### Is Native Messaging enabled

Checks whether the conditions for displaying the Native Messaging tab are met.

These conditions include:

- Whether the messaging preference key is enabled.
- Whether the history contains messages.

!!! note "This does not mean that the Messaging tab is currently displayed."

**Type:** `isNativeMessagingEnabled`

No fields.

```json
{
    "@": "isNativeMessagingEnabled"
}
```

!!! note "Added in 26.2"

---

#### Is Conferencing enabled

Checks whether the conditions for displaying the Conferencing tab are met.

These conditions include:

- Whether any type of conferencing is enabled.

!!! note "This does not mean that the Conferencing tab is currently displayed."

**Type:** `isConferencingEnabled`

No fields.

```json
{
    "@": "isConferencingEnabled"
}
```

!!! note "Added in 26.2"

