> For the complete documentation index, see [llms.txt](https://docs.saleschat.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.saleschat.pro/principles/lead-assignment.md).

# Lead assignment

How a lead is assigned to a human agent, when Saleschat shows chats to that human agent, and what happens when assignments overlap.

Each lead in Saleschat belongs to one human agent at a time. Your CRM and your journeys can assign leads, and so can users in the dashboard, depending on their role and your org's lead reassignment settings.

## Assigning a lead and showing chats

Assigning a lead records which human agent the lead belongs to. Saleschat **shows chats** when it adds that human agent as a participant to the lead's chat. Only then can the human agent and their managers see the conversation and reply.

An assignment is either immediate or deferred:

* **Immediate assignment** shows chats straight away. Any other human agent in the chat is removed.
* **Deferred assignment** records the assignment now and shows chats later, when the lead replies or an AI agent hands the lead over. While the assignment waits, the lead appears as assigned, with the assignment deferred, to the named human agent or to the team that will pick one.

Once a lead's chats have been shown, every later assignment of that lead is immediate, whichever way it's made. A deferred assignment has no time limit: if the lead never replies, it keeps waiting. To show chats sooner, assign the lead with the Assign API or reassign it in the dashboard.

## Ways to assign a lead

Some ways name a human agent. Others name a team, and the journey's assignment handler picks a human agent from it, as described in [How an assignment handler picks a human agent](#how-an-assignment-handler-picks-a-human-agent). A way marked deferred is deferred only until the lead's chats have been shown; after that, it assigns immediately.

| Way                                                                                                               | Who gets the lead                                                                                                                                                                                           | Assignment |
| ----------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| The [Assign API](https://docs.saleschat.pro/api-documentation/leads.md)                                           | The human agent named by `user_id` or `user_email`                                                                                                                                                          | Immediate  |
| Assign or reassign in the dashboard, from **Search**, **Response Delays**, or **Reassign Chatroom** inside a chat | Any user you choose                                                                                                                                                                                         | Immediate  |
| A lead event with an assignment key                                                                               | The human agent named in the event                                                                                                                                                                          | Deferred   |
| A campaign that names a human agent                                                                               | That human agent                                                                                                                                                                                            | Deferred   |
| An App send, automation, or campaign                                                                              | A human agent picked when the lead replies, by the journey's assignment handler or, if it has none, as described in [Unassigned leads and deleted human agents](#unassigned-leads-and-deleted-human-agents) | Deferred   |
| An inbound rule, for a new inbound message from a lead with no human agent                                        | A human agent picked by the inbound rule's assignment handler or, if it has none, as described in [Unassigned leads and deleted human agents](#unassigned-leads-and-deleted-human-agents)                   | Immediate  |

Who can reassign from the dashboard depends on the user's role and on your org's lead reassignment settings. See [Reassign a lead](https://docs.saleschat.pro/application/teams/operations.md#reassign-a-lead).

### Assignment keys on lead events

Use assignment keys on disposition events, mainly after a call that didn't connect (a Not Connected, or NC, disposition):

* **If the lead already belongs to a human agent in your CRM or dialler**, add that human agent to the NC event with an assignment key. The assignment is deferred, so the lead appears in the human agent's chat list only once the lead replies, and their list isn't filled with leads who haven't responded.
* **If your dialler runs in progressive or predictive mode** and hasn't given the lead to a human agent yet, send the NC event without an assignment key. When the lead replies, Saleschat assigns it as described in [Unassigned leads and deleted human agents](#unassigned-leads-and-deleted-human-agents).

The Assign API always assigns immediately, so a deferred assignment can only come from an event or a journey.

To assign a lead through an event, add one of these keys to the event's attributes:

* `sc_assigned_user_id`: the human agent's Saleschat user ID.
* `sc_assigned_email_id`: the human agent's email address.

If an event has both keys, Saleschat uses `sc_assigned_user_id`. Keys are matched regardless of case, and any event name can carry them. Saleschat reads the key from that event only, not from the lead's attributes or an earlier event. The [Basic CRM integration tutorial](https://docs.saleschat.pro/getting-started/basic-crm-integration-tutorial.md#record-lead-events) has an example.

### Deleted and disabled users

The Assign API, lead events, and campaign file uploads reject a human agent whose user has been deleted. If the user is deleted while a deferred assignment is waiting for them, Saleschat assigns the lead as described in [Unassigned leads and deleted human agents](#unassigned-leads-and-deleted-human-agents).

A disabled user still receives leads, the same way a disabled mailbox can still receive email. When a human agent leaves your org, delete their user and reassign their leads, as your dialler reassigns them.

## When assignments overlap

* **An immediate assignment cancels a deferred one.** When a lead is assigned with the Assign API or in the dashboard while a deferred assignment is waiting, the deferred assignment is cancelled and Saleschat shows chats to the new human agent.
* **A newer deferred assignment replaces an older one.** If another deferred assignment arrives before the lead replies, only the newer one is kept. Naming the same human agent again changes nothing.
* **An automation assigns after the event that started it.** When an event with an assignment key starts an automation that has an assignment handler, the key assigns the lead first and the automation's handler assigns it next, so the handler's pick replaces the key's. An automation without a handler doesn't replace the key's assignment.

## How an assignment handler picks a human agent

An assignment handler is a set of rules, attached to a journey, that picks a team for a lead and then a human agent from that team. You set handlers up in **Settings** > **Assignment Handlers**, as described in [Assignment handlers](https://docs.saleschat.pro/application/teams/operations.md#assignment-handlers). A handler is optional. When a journey without one needs to assign a lead, Saleschat chooses a handler as described in [Unassigned leads and deleted human agents](#unassigned-leads-and-deleted-human-agents).

The handler checks its rules from top to bottom, and the first rule that matches the lead's attributes picks a team. If no rule matches, the fallback handler assigns the lead. If the team a rule picks has no members, the lead stays queued until you add members or fix the rule or integration that routes leads to that team. Changes to a team's members take effect within 5 minutes.

Saleschat then picks a human agent from the team, following the handler's settings:

* **User Stickiness** sends the lead back to the human agent who handled it last. It always applies, unless that human agent's user has been deleted.
* **Online status** always applies: when the handler requires human agents to be online, only online human agents can be picked. A human agent goes online or off shift with the status switch next to their name in the dashboard's left panel, which shows **Online**, **Idle**, **Off shift**, or **Not connected**. When the handler's **Require agent online** setting is on, their Saleschat tab must also be open and connected.
* **Without stickiness**, Saleschat picks any available human agent in the team: one who meets the handler's online setting and its other availability settings.

If no human agent is available, the lead stays queued until one is, with no time limit.

{% hint style="info" %}
A dashboard alert for queued leads that haven't been assigned is coming in a future release.
{% endhint %}

The fallback handler has no team. It picks from everyone in your org, in role order: users with the Member role first, then Manager, then Admin, then Owner, with the same stickiness and online rules.

## Unassigned leads and deleted human agents

A lead can be left without a human agent when it has never been assigned, for example after a call that didn't connect, or when the human agent it's assigned to has been deleted. Saleschat assigns such a lead only when something triggers an assignment, such as an inbound message from the lead or a journey that reaches it. Until then, nothing changes. When it's triggered, Saleschat checks your assignment handlers in the order they're listed in **Settings** > **Assignment Handlers**, and each handler's rules from top to bottom. The first rule that matches the lead's attributes picks the team. If no rule matches, the fallback handler assigns the lead.

## When an AI workflow ends

An AI workflow ends in one of two ways, and the journey that started it decides what happens next:

* **The AI agent hands the lead over.** A handover always brings in a human agent. Saleschat assigns the lead immediately, to the human agent the journey names or to one picked by the journey's assignment handler. If the journey has neither, Saleschat assigns the lead as described in [Unassigned leads and deleted human agents](#unassigned-leads-and-deleted-human-agents).
* **The AI agent resolves the conversation without a handover.** No human agent is needed now, so the journey sets a deferred assignment, to the human agent it names or through its assignment handler. If the lead needs a human agent later, that deferred assignment applies. If the journey has neither, the lead follows [Unassigned leads and deleted human agents](#unassigned-leads-and-deleted-human-agents).
