# About Redistribution of Chats from Operator

Redistribution of chats allows automatically redistributing chats from an operator to other available operators in case of force majeure circumstances, such as power outage, technical failures, or other situations when an operator cannot process dialogs.

---

## Context and Problem

In many cases, an operator cannot process dialogs due to force majeure circumstances:
- Power or internet outage
- Technical failures on operator's side
- Unforeseen situations
- Quick response needed to minimize negative impact on support quality

Redistribution of chats solves this task by allowing automatic redistribution of chats to other available operators.

---

## Key Concepts

### Redistribution Process

**Creating Process:**
1. Create a new bot section
2. Be sure to check **"Use as Process"**
3. Configure the process scenario

**Configuring Process Scenario:**
1. Notification to user about transfer to another operator
2. Action `setOperatorStatusToOffline` to set operator status to Offline
3. Action `goto_alias` to transition to redistribution alias

**Configuring Main Scenario:**
- Specify alias for redistribution
- Add auto-distributed connection with operator
- Specify weight (`weight` parameter) for prioritization

### Launching Process

The process is launched manually:
1. Select the needed operator in operator panel
2. Right-click (RMB)
3. Select **"Launch Process"**
4. Select the needed process and launch it

---

## Approach Options

### Redistribution Through Process vs Manual Redistribution

**Redistribution Through Process:**
- ✅ Pros: Automation, standardization, ability to launch for groups of operators
- ❌ Cons: Requires prior configuration

**Manual Redistribution:**
- ✅ Pros: Flexibility, control
- ❌ Cons: Slowness, requires manual intervention

**Why We Use Process:**
Process allows standardizing redistribution and launching it for groups of operators, topics, or folders, ensuring efficiency and quick response.

---

## Adopted Solutions

### Using Weight for Prioritization

When redistributing, it's important to specify weight (`weight` parameter) for prioritizing chats that could not continue communication with the operator. The higher the weight value, the higher the priority during distribution.

### Setting Operator Status to Offline

The `setOperatorStatusToOffline` action sets operator status to Offline so that subsequent chats are not distributed to them until their connection is restored.

---

## Implications for Users and Implementation

### For Integrators

When configuring redistribution, it's important to:

1. **Create process** — with mandatory "Use as Process" checkbox
2. **Configure process scenario** — with message, `setOperatorStatusToOffline`, and `goto_alias`
3. **Configure main scenario** — with alias and weight for redistribution
4. **Test process** — verify correct operation

### Common Errors

**Error:** Process does not launch  
**Problem:** "Use as Process" checkbox is not checked  
**Solution:** Check section settings and check the checkbox

**Error:** Chats are not redistributed  
**Problem:** Alias or weight is not configured in main scenario  
**Solution:** Check alias and weight settings in main scenario

**Error:** Operator continues to receive new chats  
**Problem:** `setOperatorStatusToOffline` is not executed or incorrectly configured  
**Solution:** Check execution of `setOperatorStatusToOffline` and its configuration

---

## Usage Examples

### goto_alias Configuration

```json
{
  "alias": "redistribute_chats"
}
```

### Configuration with Weight

```json
{
  "auto_connect_operator": true,
  "subject_alias": "support",
  "weight": 1000
}
```

---

## Related Documents

- **Explanation:** [Automatic Connection of Free Operator](/en/operatorline/explanation/auto-connect-free-operator.md) — configuring automatic connection
- **Explanation:** [Auto-Distribution of Dialogs](/en/operatorline/explanation/auto-distribute-dialogs.md) — detailed information about auto-distribution
- **Explanation:** [Connecting Chat with Operator](/en/operatorline/explanation/connect-chat-to-operator.md) — configuring connection to operator

