> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getlurk.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Build a rule

> Make a draft rule in the dashboard, finish it in the sentence editor, preview it on the last 30 days, and see which role can do each step.

A rule is one sentence you can change in place: **When** an event happens, **if** conditions hold, **give** these units, at most so many times. This page is the click path. The clauses and what they mean are on [Rules](https://docs.getlurk.com/rules.md).

Everything here makes a **draft**. A draft listens to nothing, so nothing changes for your users until a person takes it live ([Go live](https://docs.getlurk.com/dashboard/go-live.md)).

> [!NOTE]
>
> An owner, an admin or a developer can make, edit, preview, rename and duplicate a rule. A viewer can look but not change anything, and is not offered **New rule**. Taking a rule live is for an owner or admin only.

## Make a draft

**1. Open Rules and choose New rule**

In the sidebar, open **Rules**. Select **New rule**, top right. The list is filtered by **All**, **Live**, **Paused** and **Drafts**, and **Search rules** finds one by name. A project with no rules shows "No rules yet" and a **See templates** link.

**2. Name it, say what starts it, say what it gives**

In the popover, type a **Name**. Choose what starts the rule: **An event**, **A balance** or **A time**. Under **What it gives**, pick a unit, and set the amount under **Give**. Only units that can go up are listed. If there are none, the list says "No unit can be given yet. Make one on Units first."

**3. Select Make a draft**

The new rule opens on its own page, as a draft. The page shows its key under the sentence, for example `morning-regular`. The key is what the API, Activity and other rules call it by, and it cannot change.

## Pick the event

On the rule's page, select the event in the sentence (the first chip, "Change what starts it"). The **Event** box says "Search events, or type a new name".

* **Your events** lists the names your app has sent in the last 30 days, or that a rule listens for, each with how often it came in ("12 in 30 days").
* To use a name your app has not sent yet, type it and choose **Use a new event name**. It must be lowercase words joined by dots, thing first, like `checkin.scanned`. The box says what is wrong when it is not.
* Under the box, the event's properties are shown with what each holds. The same list is `GET /v1/events/catalog`: [the event catalog](https://docs.getlurk.com/events.md#the-event-catalog).
* Chat events (`chat.*`) belong to chat, which is not available yet. When it is, the editor also picks their property values: the platform (Discord, Slack or Telegram, each marked if your project has no community there, which would never match), your community by name, or a channel by name (the channel's ID is what is saved, and an ID can be typed), and the sentence reads "it's on Discord" or "it's in #general".

Wherever the rule names a property of the event (a condition, or an amount taken from the event), the editor suggests the properties the event carries. Only numbers are suggested for a range or an amount. You can still type a name it has not seen.

### Offer a property's values in a list

A value of your own events is typed by hand. A typo in a value (`Pro` for `pro`) is a rule that never fires. To get a list instead, open **Events** in the sidebar, open the event, and switch on **Remember values** for that property. Lurk then keeps up to 20 of its values and the editor offers them, still taking another. Only an owner or admin can change these. What is kept, what is refused and how to delete it: [Remember values](https://docs.getlurk.com/events.md#remember-values).

## Add conditions, a limit and more actions

In the sentence, use the add buttons:

* **Add a condition** offers **Hours** (when in the person's day), **An event property** and **A number in the event**, plus **An audience** once the project has audiences and **A balance** once it has units. A rule on a time has no event, so the two event items are not for it.
* **Add an action** offers **Give** for each unit, **Streak** (count a day, or start over if a day was missed), **Back to 0** for a unit that allows it, and **Ask a person first**, which holds any change above a number you pick until someone decides. A rule on a time cannot hold a change, so it is not offered there. The held change shows up in [Activity](https://docs.getlurk.com/dashboard/read-activity.md#held-changes). Each extra action has an × to remove it.
* **Add a limit** offers "1 per user per day", "1 per user per week", "1 per user per month" and "Once per user, ever". Select the limit chip to change the number or the period. With no limit, the sentence says "no limit".

Click any chip in the sentence to change it. [Rules](https://docs.getlurk.com/rules.md) has the JSON for each clause.

## Save as a new version

Editing a rule does not change it at once. Once you change something, a banner reads "Not saved yet." with **Discard** and **Save as version N**, where N is one more than the current version. For a draft, "Nothing changes for users until it goes live." For a live rule, the version that is running keeps running until you take the new one live.

If someone else saved a version while you were editing, the page offers **Load their version** or **Keep mine**. Leaving the page with an unsaved edit asks first: **Keep editing** or **Leave**.

## Preview before you go live

Select **Preview**, top right of the rule. The panel is marked "Nothing is given" and shows what the rule would have done to your events over the last 30 days: **Would give** (or **Would take**), **Users reached**, and **Skipped**, the events it did not apply to. **Close preview** shuts it.

A rule that starts on a balance or on a time has no event to replay. Its preview lists what starts it, or the next times it runs in the project's time zone.

## Rename and duplicate

* Select the pencil by the name (**Rename**) to rename the rule, then **Save**. A name belongs to the rule, not to a version, so it takes effect at once, makes no new version and works on a live rule too (up to 80 characters). `PATCH /v1/rules/{id}` with only `name` does the same. The key (`morning-regular`) is shown and cannot be changed. Everything else about a live rule goes through a new version.
* Open the **More actions** menu (the dots) and choose **Duplicate**. It makes a new draft called "Copy of …" with the same newest version (`POST /v1/rules` with that definition), and opens it. Nothing runs until a person takes it live.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.