# Automate routine work with rules

Automations do the repetitive parts of support for you: they **route**, _tag_, assign and reply the moment a conversation matches your conditions. This guide walks through building one, then covers every option the rule builder offers. If you are new to Relaypoint, read [Get to know Relaypoint](docs:page/dpage_isrolpkrismr21ah) first.

:::info Available on Team and Business
Automations are included in the **Team** and **Business** plans. Starter workspaces can build rules but can't turn them on. Compare plans in [Account & billing](docs:section/dsec_rbvxvcniyeqhjh6w).
:::

## How a rule works {#how-rules-work}

Every rule has three parts, always in this order:

1. **When**: the trigger, such as _a conversation is created_ or _a customer replies_.
2. **If**: one or more conditions. All of them must match.
3. **Then**: the actions Relaypoint performs, top to bottom.

![The automation builder with a When, If and Then block filled in to route billing questions to the Finance team](https://demo-doc-site.clevera.help/media/278da8a7cf829d6a5d802fe9cfb0fa8fa0bfffefbb29746434b63f526772341f.png "A rule that sends billing questions to the Finance team")

Rules run in the order they appear on the **Automations** page. A rule can stop later rules from running with the `stop_processing` action. Since version 2.4, rules run in under ==200 ms== on average.

## Build your first rule

:::steps
### Open the builder

Go to **Settings › Automations** and select **New automation**.

### Name the rule

Give it a name your team will recognise, e.g. `Route billing questions to Finance`.

### Pick a trigger

Choose **A conversation is created**. Other triggers are listed in [Triggers](#triggers).

### Add conditions

Add `Subject contains invoice, refund, billing`. Add a second condition `Customer plan is Team or Business` to skip free accounts.

### Choose actions and save

Choose **Assign to team › Finance**, then select **Save automation**. The rule is on as soon as it's saved.
:::

:::tip Test before you trust it
Select **Run on past conversations** and pick the last 7 days. Relaypoint shows which conversations _would_ have matched, without changing anything.
:::

---

## Reference

### Triggers {#triggers}

| Trigger               | Fires when                                | Typical use                 |
| :-------------------- | :---------------------------------------- | :-------------------------- |
| Conversation created  | A new email, chat or API message arrives  | Routing, tagging            |
| Customer replied      | The customer answers an open conversation | Reopen, notify the assignee |
| Conversation idle     | No reply for a set time (e.g. `48h`)      | Reminders, auto-close       |
| Tag added             | Someone adds a tag                        | Escalations                 |
| Satisfaction received | A CSAT rating comes in                    | Follow up on low scores     |

### Conditions

You can combine conditions on:

- **Message fields**
  - Subject, body, sender address
  - Channel (email, chat, API)
- **Customer fields**
  - Plan, country, language
  - Any custom attribute, such as `account_tier`
- **Time**: business hours, weekday, or the conversation's age

#### Matching text

Text conditions are case-insensitive. `contains` matches any of a comma-separated list; `matches` takes a regular expression.

##### Regular expression flavour

Relaypoint uses RE2 syntax. Look-behind isn't supported.

###### A note on performance

Very long expressions are slower. Keep each one under 500 characters.

### Actions

:::tabs
@tab Assign

Assign to a person, a team, or **round robin** inside a team. Round robin skips people marked _away_.

@tab Tag

Add or remove one or more tags. Tags you type that don't exist yet are created.

@tab Reply

Send a saved reply. Placeholders such as `{{customer.first_name}}` are filled in for you.

@tab Webhook

Send the conversation to your endpoint as JSON. See [Integrations & API](docs:section/dsec_az9e5fjk9tfgbsxy).
:::

## Rules as code

Teams that keep their configuration in version control can export and import rules as YAML or JSON.

:::tabs
@tab YAML

```yaml
name: Route billing questions to Finance
trigger: conversation.created
conditions:
  all:
    - field: subject
      op: contains
      value: [invoice, refund, billing]
    - field: customer.plan
      op: in
      value: [team, business]
actions:
  - assign_team: finance
  - add_tag: billing
```

@tab JSON

```json
{
  "name": "Route billing questions to Finance",
  "trigger": "conversation.created",
  "conditions": {
    "all": [
      { "field": "subject", "op": "contains", "value": ["invoice", "refund", "billing"] },
      { "field": "customer.plan", "op": "in", "value": ["team", "business"] }
    ]
  },
  "actions": [{ "assign_team": "finance" }, { "add_tag": "billing" }]
}
```

@tab CLI

```bash
relaypoint rules import ./rules/billing.yaml --workspace acme-support
relaypoint rules list --format table
```
:::

## Examples

:::details Auto-close conversations after 5 days of silence
Trigger **Conversation idle** with `5d`, condition `Status is Waiting`, actions **Send saved reply › Closing note** then **Close**.
:::

:::details Escalate unhappy customers
Trigger **Satisfaction received**, condition `Rating is 1 or 2`, actions **Add tag › escalation** and **Notify › Support leads**.
:::

:::details Route by language
Trigger **Conversation created**, condition `Customer language is German`, action **Assign to team › DACH support**.
:::

## Good practice

> Start with one rule that saves your team ten minutes a day. Add the next one only when the first has run for a week without surprises.
>
> — The Relaypoint support team

- [x] Give every rule a descriptive name
- [x] Test on past conversations before you turn it on
- [ ] Review rule hit counts once a month
- [ ] Remove rules nobody remembers creating

:::note
Disabled rules keep their history, so you can turn them back on later.
:::

:::warning Loops
A rule that adds a tag and a second rule triggered by that tag can call each other forever. Relaypoint stops a chain after **10** steps and flags both rules.
:::

:::danger Deleting a rule can't be undone
Deleted rules and their run history are removed for good. Disable a rule instead if you might need it again.
:::

:::success You're set
Your first rule is live. Watch it work in **Reports › Automations**.
:::

## Watch it in action

A short walkthrough of building and sharing a dashboard, recorded with dummy data:

::clevera-video{id="scrcst_6pqzqkcbpe8rbfw1"}

## Also good to know

Inline formatting the editor supports: **bold**, _italic_, ~~strikethrough~~, `inline code`, ==highlight==, H:sub[2]O, x:sup[2], and math such as $$t_{reply} = t_{first} - t_{created}$$.

:::columns{cols=2 ratio="1:1" gap=md valign=center}
@column

### Need a hand?

Our team reviews rules for Business customers for free. Book a 20-minute session and we'll check your setup.

@column

![The Relaypoint inbox with seven open conversations, each tagged Billing, Bug, How-to or Feedback](https://demo-doc-site.clevera.help/media/eec1a637c56d384dcaab23af27e21d1e0613fc7f3706bb1cacba987d1f39a1ad.png "Routed conversations land in the right view")
:::

:::cards{cols=3 style=boxed}
- [Getting started](docs:section/dsec_iihmde5tw5cnzenr) icon=rocket — Set up your workspace in ten minutes
- [Integrations & API](docs:section/dsec_az9e5fjk9tfgbsxy) icon=network — Connect your tools and build on the API
- [Troubleshooting](docs:section/dsec_uudhqlz20icneyyk) icon=tools — Fix the most common problems
:::

:::faq
### Can a rule run on conversations that already exist?

Yes. Use **Run on past conversations**, choose a date range and confirm. Up to 10,000 conversations per run.

### How many rules can I have?

Team workspaces can have 50 active rules; Business workspaces have no limit.
:::

:::cta{tone=brand align=center}
## Still stuck?

Our support team answers within one business day.

::button[Contact support]{href="docs:contact" variant=primary icon=chat-bubble}

::button[Search the docs]{href="docs:search?q=automations" variant=secondary}
:::
