units.create. Drafts, edits and going live refuse a missing unit with validation_failed, naming the unit and its exact field.
Rules start as drafts. A key can create and preview them. Only an owner or admin takes one live, in the dashboard. A key or an agent that tries gets
approval_required; it can propose the change, and an owner or admin approves it.Building a rule in the dashboard
The dashboard picks the event, the properties and their values for you, and offers the values you asked Lurk to remember. The click path, including renaming and duplicating a rule, is on Build a rule. The list it picks from isGET /v1/events/catalog: the event catalog.
Conditions on an event’s own numbers and values
{ "property": { "name": "channel", "equals": "web" } } matches a property exactly. For a number, { "property_range": { "name": "messages", "gte": 5 } } asks for at least five; lte asks for at most, and both together for a range, ends included. A property that is missing, or is not a number, never passes a range. A rule on the clock has no event, so it cannot use either.
A streak counts days in a row
An action can count days instead of giving a number. The unit’s balance is the streak, so anything that reads a balance reads it.extendadds one if yesterday was counted, starts at 1 again after a missed day, and does nothing a second time in a day. Days are the person’s own days.- Give a bonus with a rule that follows the streak:
{ "unit": "streak", "reaches": 7 }. resetsets the streak to 0 for anyone who missed yesterday. Run it from a rule on a schedule, each morning:{ "schedule": { "every": "day", "at": "00:05" } }. Without it, a missed day shows the next time the person comes in.
A rule can set a unit back to 0
An action{ "unit": "xp", "reset": true } sets a unit back to 0 for everyone it reaches, whichever way the unit goes. The unit has to allow it, and a schedule usually starts it. Resets has the example, the receipts it writes and what it leaves alone.
A rule says whose word it takes
Every event and receipt knows where it came from:trusted (your server’s key or an agent, a person in Lurk, or Lurk itself) or untrusted (a device). A rule says which it takes, as an if clause, a ladder:
- A rule on a
chat.event must have asource, and the name must be one Lurk defines (the event catalog): a mistypedchat.checknis refused when you save it, unlesssourceistrustedfor your own server’s events. - A schedule has no event, so a
sourceon it is refused. A rule that follows a balance reads the source of the event that started its chain. - A preview and a replay judge each past event by the source it arrived with.
source: "platform"), a rule’s chat effects and devices’ events are not available yet.
A rule can be changed for some people
modify changes what a rule gives, for the people it is for. “VIPs get double on every order”:
- Each modifier has
if(who it is for, every clause must hold), and eithertimes(multiplies) orbonus(adds).unitlimits it to one unit the rule adds; leave it out for all of them. - They apply in the order written, after the rule’s own amount: a rule that gives 50 with
times: 2thenbonus: 20gives 120; with the two the other way round it gives 140. - For anyone they are not for, they do nothing and the rule still runs. The receipt says which applied:
×2 (user is in vips): 50 → 100 beans. - They change only what a rule gives (
add), not takes or streaks. The amount they make is what the unit’s cap, the rule’s budget and its hold threshold are checked against.