# How to Configure Operator Panel Webhook

Operator panel webhook allows receiving events from the operator panel (chat creation, operator connection, chat closure) to your external service. This is useful for synchronizing dialogue statuses with a CRM system or logging events.

---

## When to Use Operator Panel Webhook?

Operator panel webhook is suitable for such cases:

- You need to track events in the operator panel (chat creation, operator connection)
- You need to synchronize dialogue statuses with your CRM system
- You need to log operator panel events to an external system
- You need to integrate with an analytics system

---

## Configuration

### Step 1: Specify Webhook URL in Action

In the `operator_panel__connect_to_operator_with_msg` action, specify the `event_webhook_url` parameter.

**Configuration example:**

```json
{
  "auto_connect_operator": true,
  "subject_alias": "support",
  "event_webhook_url": "https://your-service.com/webhook/operator-events"
}
```

### Step 2: Configure Processing on Your Service

Your service should:

1. Accept POST requests to the specified URL
2. Verify request authenticity (if necessary)
3. Process different event types
4. Return status code 200 for successful processing

**Processing example (Node.js):**

```javascript
app.post('/webhook/operator-events', (req, res) => {
  const event = req.body;
  
  switch (event.event_name) {
    case 'chat_created':
      // Process chat creation
      console.log('Chat created:', event.chat_id);
      break;
    case 'operator_connected':
      // Process operator connection
      console.log('Operator connected:', event.operator.id);
      break;
    case 'chat_closed':
      // Process chat closure
      console.log('Chat closed:', event.chat_id);
      break;
  }
  
  res.status(200).json({ status: 'ok' });
});
```

---

## Event Types

The following events will be forwarded to the specified URL address:

- `chat_created` — chat created
- `auto_connected` — auto-connection of operator
- `operator_connected` — operator connected
- `operator_disconnected` — operator disconnected
- `chat_closed_by_operator` — chat closed by operator
- `chat_closed` — chat closed
- `chat_closed_by_timeout` — chat closed by timeout
- `connection_timeout` — connection timeout
- `delegate_chat_on_skill_group` — delegate dialogue to another skill group
- `chat_transferred_to_operator` — transfer dialogue to another operator

---

## Event Format

Event format is the same as in Custom Channel. All events contain `text` and `event_name` fields.

### Example `chat_created` Event

```json
{
  "reply_markup": {
    "remove_keyboard": false
  },
  "chat_id": "34122",
  "text": "Chat created",
  "event_name": "chat_created",
  "client": {
    "id": 572338,
    "first_name": "Test",
    "last_name": "Surname",
    "username": "testuername",
    "language_code": "uk",
    "phone": "+380505776464",
    "channel": "telegram"
  },
  "id": "83317aa1-8ea4-4c05-afed-d7437ff88fbf",
  "from": "bot",
  "bot_id": 4,
  "type": "text"
}
```

### Example `operator_connected` Event

```json
{
  "reply_markup": {
    "remove_keyboard": true
  },
  "chat_id": "34122",
  "text": "Operator connected",
  "event_name": "operator_connected",
  "client": {
    "id": 572338,
    "first_name": "Test",
    "last_name": "Surname",
    "username": "testuername",
    "language_code": "uk",
    "phone": "+380505776464",
    "channel": "telegram"
  },
  "operator": {
    "id": 25,
    "first_name": "Root",
    "last_name": "Admin",
    "avatar_img": "https://example.com/avatar.png",
    "role": "admin",
    "kw_user.email": "operator@example.com"
  },
  "id": "baebdeec-e7b7-4188-bd1d-409f4133507f",
  "from": "bot",
  "bot_id": 4,
  "type": "text"
}
```

---

## Differences from Custom Channel

**Operator Panel Webhook:**
- Configured directly in the `operator_panel__connect_to_operator_with_msg` action
- Sends only events from the operator panel
- Does not require separate channel configuration

**Custom Channel:**
- Requires channel configuration in bot settings
- Sends all messages and events
- More flexible for full integration

---

## Limitations

- URL must be accessible from the ConnectiveOne server
- Only HTTP and HTTPS protocols are supported
- Request timeout depends on system settings
- It is recommended to use HTTPS for security

---

## Related Articles

- [Integration via Custom Channel](/en/integrations/how-to/custom-channel/integrate-via-custom-channel.md)
- [What are integrations](/en/integrations/explanation/what-are-integrations.md)
- [Connect chat to operator](/en/operatorline/explanation/connect-chat-to-operator.md) — configuring connection to operator

