﻿# Conditions

Conditions determine when [functions](function-reference.md) should execute or when UI elements (such as [Buttons](buttons.md)) should be displayed. They evaluate criteria against real-time application state and can be combined using logical operators to express complex rules.

## JSON Schema

Schema for condition definitions is available [here](https://schemas.acrobits.net/core/functions/condition.json).

---

## 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.

**Type:** `variable`

| Field | Type | Description |
|-------|------|-------------|
| `name` | String | Variable name. Can include a scope prefix (see [Scopes](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 if the current call scope refers to a conference. Returns true when the scope is a call that is part of a conference and the scope is not resolved 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. If **Random** is used in a reactive context, the `intervalMilliseconds` can be used to control the refresh rate.

**Type:** `random`

| Field | Type | Description | Default |
|-------|------|-------------| ------- |
| `intervalMilliseconds` | int | How often the random value should change. If set to 0, the value will not refresh at all. *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 messaging prefkey is turned on
* Whether there are messages in the history

!!! note "This doesn't mean that the messaging tab is actually being 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 turned on

!!! note "This doesn't mean that the conferencing tab is actually being displayed."

**Type:** `isConferencingEnabled`

No fields.

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

!!! note "Added in 26.2"