# Groups and routing

> Set up groups for your teams, and routing rules that send each new ticket to the right group or person as it arrives.

A group is a team, such as Billing or Technical support. A routing rule looks at each new ticket and sends it to a group, a person, or both. Administrators set up groups under **Settings → Groups** and rules under **Settings → Routing**.

## Groups

### Add a group

1. Go to **Settings → Groups** and click **Add group**.
2. Enter a **Name** and, if you like, a **Description** of what belongs there.
3. Under **Members**, tick the people in the team.
4. Click **Add group**.

Only people who can work tickets are listed: read-only seats can't be members. A person can be in any number of groups. The **Groups** page lists each group with its members and how many open tickets it holds. Click **Edit** to rename a group or change its members.

### What a group does

- The queue shows each ticket's group, and its **Group** filter shows one group's tickets.
- While nobody is assigned to a ticket, a customer's message on it notifies the group's members who asked to hear about unassigned tickets, instead of everyone in the workspace. See [Email notifications](https://www.lagottolabs.ai/support/notifications/email-notifications.md).
- On the **Dashboard**, the **Unassigned** list shows tickets in your groups and tickets in no group.

Groups don't limit who can see or work on a ticket. Anyone with a full seat can open, answer and assign any ticket.

> **Note:** A group with no members means nobody is notified about its unassigned tickets.

### Delete a group

Open the group with **Edit** and, at the bottom of the page, click the delete button named after the group, such as **Delete Billing**, then confirm. Its tickets stay where they are with no group, and routing rules that sent tickets to it lose their group too.

A rule left with nowhere to send tickets, because it assigns nobody or only someone who has been deactivated, is switched off. The message after you delete the group names each one. To use one again, edit it, choose another group or a person, and turn it back on. A rule that also assigns tickets to an active person stays on and keeps assigning them, now without a group.

## Routing rules

With no rules, every new ticket arrives with no group and nobody assigned.

### How rules run

- Rules run when a ticket is created from a customer's email or through the API, and once more when its language is detected. See [Rules on Language](https://www.lagottolabs.ai/support/tickets/groups-and-routing.md#rules-on-language). They don't run again when the customer replies, and they don't run on a ticket you open yourself with **New ticket**, which is assigned to you.
- They're checked from the top of the list down. The first rule that matches decides, and the rest are skipped.
- A rule that's switched off is skipped.
- A rule with nowhere to send tickets is skipped too, so the rules below it still get their turn: one with no group that assigns nobody, or only someone who has been deactivated. The routing page flags it.
- Changing or deleting a rule doesn't move tickets it has already routed.

### Add a rule

1. Go to **Settings → Routing** and click **Add rule**.
2. Give it a **Name** that says what it does, such as "Refunds go to Billing".
3. Under **When a new ticket matches**, choose **all of these** or **any of these**.
4. Fill in a condition: a field, a comparison and a value. Click **Add condition** for another, or the **×** beside one to remove it.
5. In **Send it to**, choose a group. In **And assign it to**, choose a person if you want one. A rule needs at least one of the two. Leave the person empty to let the group pick the ticket up.
6. Check that **This rule is on** is switched on, and click **Add rule**.

### Conditions

Each condition compares one field of the new ticket:

- **Subject**
- **Message**: the customer's first message, the one that opened the ticket
- **Customer's email**, such as `jordan@example.com`
- **Customer's email domain**: the part after the @, such as `example.com`
- **Language**: the language the customer wrote in, as a code such as `es`, `fr` or `de`

The comparisons are **contains**, **does not contain**, **is**, **is not**, **starts with** and **ends with**. Capitals don't matter, and a row with no value is ignored.

For example, a rule matching **any of these** with **Subject contains** `refund` and **Message contains** `invoice` sends billing questions to your Billing group. The routing page shows each rule in words: "When subject contains “refund” or message contains “invoice” → Billing".

### Rules on Language

A ticket's language isn't known when it arrives. It's detected shortly afterwards when [translation](https://www.lagottolabs.ai/support/ai/translation-and-summaries.md) is switched on, or when AI writes a draft reply on the ticket. See [AI drafts](https://www.lagottolabs.ai/support/ai/ai-drafts.md).

- Until the language is detected, a **Language** condition isn't met, whatever the comparison, **is not** and **does not contain** included. A rule matching **any of these** can still match on its other conditions.
- When the language is detected, the rules run again. If a rule with a **Language** condition now comes first, the ticket moves to that rule's group and person, as if it had just arrived. When that rule names no person, someone an earlier rule assigned the ticket to is unassigned.
- The people the ticket moves to are emailed about the customer's message as if it were new, unless they already were or someone has answered it. See [Email notifications](https://www.lagottolabs.ai/support/notifications/email-notifications.md).
- The rules don't run again on a ticket someone has moved to a group or assigned by hand, on a closed or spam ticket, or when the language changes later.
- A rule without a **Language** condition doesn't move a ticket the second time. A rule you added or changed after the ticket arrived doesn't either.

If your workspace has a rule on **Language** and nothing detects languages as tickets arrive, the routing page says so. Turn on **Translation** under **Settings → Capabilities**, or **Draft a reply when a customer writes** under **Settings → AI**. Both need AI set up: see [Setting up AI](https://www.lagottolabs.ai/support/ai/setting-up-ai.md).

### Order

Use the arrows in the **Order** column to move a rule up or down. Put narrow rules above broad ones. If "Customer's email domain is `bigclient.com`" should win over "Subject contains `invoice`", it has to come first.

### Turn off, edit or delete a rule

- **Turn off** and **Turn on** beside a rule switch it without losing it. A rule with nowhere to send tickets can always be turned off, but turns on again only once it has a group or an active person.
- **Edit** opens the rule. At the bottom of that page, the delete button named after the rule, such as **Delete Refunds go to Billing**, removes it.

If the person a rule assigns tickets to is deactivated, the routing page says so. The rule still sends tickets to its group, if it has one, but assigns them to nobody. A rule with no group then has nowhere to send tickets and is skipped until you edit it.

Changes to groups and rules are recorded in the [audit log](https://www.lagottolabs.ai/support/people-and-security/audit-log.md).
