# Routing to people

Routing gives each response an owner: the teammate who answers it. A form has rules, tried in order, and the first one that applies picks the owner, right after Mirio's read and before anything goes out. A rule can name one person or several, who take turns. The owner is @mentioned in the Slack message and in nudges, named in emails and the daily digest, shown on the response in Mirio, and sent to webhooks.

## Rules

Each rule has a condition and people:

- **The condition** is the same kind as a [destination's filter](/docs/destinations.md#filters): fit, category and [group](/docs/ai-review.md) picks from Mirio's read, and answers ("intent is enterprise"). A rule without a condition takes every response.
- **The people** are members of the workspace who have joined (an invite nobody has accepted can’t own anything). With several, they take turns: each response goes to whoever has gone longest without one from this form, and someone who never had one goes first. There's no position to reset, so editing the rules never skips anyone.

Rules are tried top to bottom. A common setup:

1. High fit → Ada.
2. Everything else → Bo and Cy, taking turns.

Put a rule without a condition last, so nothing is left without an owner. Responses that match no rule stay unassigned.

**Rules on Mirio's read need a read.** Unlike a destination's filter, a condition on fit, category or a group doesn't pass a response Mirio hasn't read (triage is off, timed out, or the form has no description of a great response, which fit needs). Those responses fall through to a later rule, usually the last one. That way "high fit goes to Ada" never hands Ada everything when triage can't run.

When someone is removed from the workspace, they come off every rule (a rule left with nobody is removed) and the responses they owned become unassigned (their Activity says so), so nothing names or @mentions them again.

### Set them in Mirio

Open the form's **Setup → Routing**: **Add a rule** picks the people and the condition; each rule has **Change** and, in its ⋯ menu, **Move up**, **Move down** and **Remove**. A new rule with a condition goes above a last rule that takes everything else.

### Set them from the CLI

```bash
npx @trymirio/mirio routing demo-request \
  --rule "fit=high => ada@acme.com" \
  --rule "=> bo@acme.com, cy@acme.com"
```

Each `--rule` is `<when> => <member emails>`, and together they replace the form's rules. The parts of `<when>` are separated by `;`, and all must match:

| Part | Means |
| --- | --- |
| `fit=high,medium` | Mirio's fit is one of these |
| `category=Sales lead,Partnership` | Mirio's category is one of these |
| `group:Urgency=This week` | a group's pick (by the group's name) |
| `intent=enterprise` | an answer, by the field's key (`answer:fit=…` for a field called `fit` or `category`) |

Leave `<when>` empty for everything else. `mirio routing demo-request` with no flags shows the rules and any warnings; `--clear` removes them; `--json` prints `{ slug, rules, warnings, changed }`.

### The API

`GET` and `PUT /v1/project/forms/{slug}/routing` with the site's secret key. `PUT` replaces the rules:

```json
{
  "rules": [
    { "when": { "fit": ["high"] }, "to": ["ada@acme.com"] },
    { "to": ["bo@acme.com", "cy@acme.com"] }
  ]
}
```

`when` takes `fit`, `categories`, `groups` (group key to picks) and `where` (`[{ "field": "<key>", "in": [...] }]`), as a destination's filter does. Up to 10 rules and 20 people each; `[]` turns routing off. An email that isn't a member who has signed in is refused, with the members who can be named. Both return `{ slug, rules: [{ when, to: [{ email, name, member }] }], warnings }`; someone who has left shows as `{ email: null, name, member: false }`. `warnings` says what would surprise you: no last rule to catch everything else, rules on fit when the form has no description of a great response, rules on triage when triage is off, and people who left.

## Who it tells

- **Slack:** the message says *Owner: @Ada* under its title, which notifies her. Mirio finds her Slack account by her email, for channels added with **Add to Slack**; otherwise, or when Slack has nobody with that address, the message names her instead. Nudges mention the owner too ("No one has replied yet · Owner: @Ada"), and the daily digest names the owner of each response still waiting, without pinging anyone.
- **Email:** notification emails say *Assigned to you* to the owner and *Owner: Ada Lovelace* to everyone else. Routing doesn't add or remove email recipients: the form's [destinations](/docs/destinations.md) decide who gets one.
- **Webhooks and the API:** every submission has `owner` (`{ userId, email, name, assignedAt }`, or `null`), in webhook payloads too.

## Changing the owner

Open a response in Mirio: **Owner** under the person's name hands it to someone else, or makes it unassigned. A form's Responses show each owner's first name, and the Filter menu has **Owner: Mine** and **Unassigned**.

From the CLI or an agent:

```bash
npx @trymirio/mirio assign demo-request sub_123 ada@acme.com   # or: none
```

That's `PATCH /v1/project/forms/{slug}/submissions/{id}` with `{ "owner": "ada@acme.com" }` (or `null`). Routing runs once per response, so a response someone assigned by hand keeps its owner.

Every change is in the response's Activity: "Routed to Ada Lovelace (rule 1)", "Eric gave it to Bo Chen", "An agent unassigned it".

## Not yet

Routing picks one owner per response. It doesn't route by territory or account, and it doesn't move a response when someone is away. A channel per category is a destination with a filter ([Filters](/docs/destinations.md#filters)), not a rule.
