Writing a condition

A condition decides when an outcome confirms. You write it as text on the task contract.

Overview

Every task has a condition in its contract. After each event, witn evaluates the condition against everything submitted for that outcome so far. When the condition locks true the outcome confirms. When it becomes impossible or a window closes without success, the outcome fails.

You write the condition as text. This guide covers the common shapes. See Conditions for the full reference.

Facts

A fact is the action of an event. On its own it is true once that event has been seen.

ticket_resolved

Combine with AND, OR, NOT

signed_by_buyer AND signed_by_seller
ticket_resolved AND NOT reopened

Use parentheses to group. NOT binds tighter than AND. AND binds tighter than OR.

paid AND (shipped OR picked_up)

Count events

COUNT(fact) counts every occurrence.

COUNT(agent_reply) >= 2

Compare a value

A bare comparison reads the latest properties.value for a fact. csat >= 4 is shorthand for csat:value >= 4.

csat >= 4

Submit the value on the event.

curl -X POST https://api.thewitn.com/v1/events \
  -H "Authorization: Bearer $WITN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "outcome_key": "...", "action": "csat", "properties": { "value": 4.8 } }'

Compare any property

Name a property after a colon to read something other than value. The part before the colon is the action, the part after is the property path.

booked_appointment:result == 5

Reach into nested objects with dots in the path.

booked_appointment:meta.score >= 0.9

Action names may contain dots, so a namespaced name still works. The colon marks where the path begins.

payment.captured:value == 5

Submit the property on the event.

curl -X POST https://api.thewitn.com/v1/events \
  -H "Authorization: Bearer $WITN_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "outcome_key": "...", "action": "booked_appointment", "properties": { "result": 5 } }'

Use == to match text.

plan == "pro"

Match one of several values with IN.

call_outcome IN ["Resolved by Agent", "Store Visit"]

Wait for quiet

G(0,24h](...) is true when its body holds for the whole window. One violation fails it.

ticket_resolved
AND NOT reopened
AND G(0,24h](NOT customer_message AND NOT human_escalation)

IDLE settles the outcome after a quiet gap. Each reset event pushes the deadline forward.

COUNT(agent_turn) >= 2 AND IDLE(agent_turn, 5m)

The line above settles 5 minutes after the last agent_turn.

Examples

A single event

downloaded

Both parties sign, nobody revokes

signed AND NOT revoked

A minimum score

csat >= 4

Multi-step verification

identity_check == "verified"
AND credit_score >= 700
AND document_signed

Validation

The condition is checked when the task is created or updated. Invalid text returns VALIDATION_ERROR with the position of the problem.

On this page