# Referral Program

The **Referral Program** tab in the builder allows you to configure the conditions for awarding credits to the referrer (the person who invited the new user).

## How it works

When a new user registers via a referral link, the system checks the configured conditions **in the order they are listed**. The first matching condition is applied: the referrer is awarded credits, and the system moves on to the next referral.

If the "Referral Program" tab is not configured, the legacy logic from the "Settings → Paid Access" section (ref_credits, ref_program) is used.

---

## Enabling / Disabling

At the top of the tab, there is a **"Referral program enabled"** toggle. If disabled, the awarding of credits based on these conditions stops completely.

---

## List of conditions

The conditions table contains the following columns:

| Column | Description |
|---------|----------|
| **Name** | A custom name for the condition |
| **Conditions** | Tags representing the new user parameters to be checked |
| **Credits** | The number of credits awarded to the referrer |
| **Completed** | Number of times the condition was triggered / total credits awarded |
| **Actions** | "Edit" and "Delete" buttons |

---

## Adding and editing a condition

Click the **"Add condition"** button in the top-right corner.

### Form fields

- **Name** — a custom description of the condition (required).
- **Language** — the new user's Telegram language code (ru, en, uk, etc.). If left blank, the language is not checked.
- **Flags** (all selected flags must be met simultaneously):
- **Premium account** — the user has Telegram Premium. 
- **Has username** — the user has a username (@login) set. 
- **Has name** — the user has a name set. - **Surname specified** — the user has a surname entered.
- **Credits** — an integer from 1 to 1,000,000 (required).

> If no flags are selected and no language is specified for a condition, it will match **any** new user.

---

## Condition evaluation logic

- Conditions are evaluated **from top to bottom** as listed in the table.
- The **first matching** condition is applied.
- All selected condition flags must be met simultaneously (AND logic).
- If no condition matches, **no credits are awarded**.

**Example of condition setup:**

1. Language: en + Login + Premium → 500 credits _(most rewarding)_
2. Language: en + Login → 200 credits
3. Language: en → 50 credits _(any English speaker)_
4. (empty condition) → 10 credits _(everyone else)_

---

## Statistics

The **"Matched"** column displays:
- **N times** — how many times the condition was triggered.
- **💎 M** — total credits awarded under this condition.

If a condition is deleted, its statistics are permanently removed.