# Dialog Tags

**Dialog Tags** are a tool for color-coding, classifying, and segmenting customer conversations in the **Chats** section. They allow you to organize incoming chats by business objectives, topics, funnel stages, or priority — both manually by support operators and automatically via bot constructor scenarios and AI.

---

## 1. What are Dialog Tags

Dialog tags are attached directly to a specific conversation with a customer (unlike contact tags/labels which are stored in the user's global profile).

### Tag Categories and Selection Types

Tags are organized into **Categories**. Each category has a designated selection type:

| Category Type | How It Works | Use Cases |
|---------------|--------------|-----------|
| **Single Selection** (Single) | Only **one tag** from this category can be active in a conversation at a time. Selecting a new tag automatically replaces the previous tag from the same category. | *Lead Status* ("Cold", "Warm", "Hot")<br>*Deal Stage* ("First Contact", "In Progress", "Paid") |
| **Multiple Selection** (Multiple) | A conversation can have **any number of tags** from this category simultaneously. | *Services* ("Botox", "Massage", "Consultation")<br>*Interests* ("Promo", "Franchise") |

Each tag has its own customizable name and badge color for instant visual recognition in the chat interface.

---

## 2. Where Tags are Configured

Tag and category configuration is located in each bot's settings:

1. Navigate to **Bots** and select your bot.
2. Open **Bot Settings** and click on the **Dialog Tags** tab.
3. In this panel you can:
   - **Create categories**: specify a name and choose the selection type (*Single* or *Multiple*).
   - **Add tags**: specify a title and choose a badge color.
   - **View Tag IDs**: each tag displays a `#ID` (e.g. `#14`), which is used in scenarios and AI integrations.
   - **Sort**: drag-and-drop categories and tags to reorder them in the menu.
   - **Edit & Delete**: if a tag or category is already assigned to active conversations, the system prevents accidental deletion and notifies you of existing associations.

---

## 3. How to Use Tags in Chats CRM

### Assigning Tags in a Conversation

1. Open a conversation in the **Chats** section.
2. Click the **+ Tag** button in the conversation header / details panel.
3. In the dropdown menu, select the desired tags. If a category is single-select, selecting a tag automatically replaces any prior tag from that category.
4. To remove a tag, click the cross icon on the tag badge or uncheck it in the dropdown menu.

> **Manager Activity Log**: tag changes made by operators in the CRM panel do not clutter the chat transcript with system messages; instead, they are recorded in the **Manager Activity** audit log (`tag_updated`).

### Display and Tooltips

- In the conversation list, tags appear as compact colored badges on each conversation card.
- If a conversation has multiple tags, they neatly collapse into a `+N` badge (e.g., `+2`). Hovering over the badge opens a tooltip with the complete list of hidden tags.

### Filtering Conversations by Tags

Above the conversation list, the filter panel includes an advanced tag filter with three matching modes:

- **All Tags (AND)** — matches conversations that have *all* of the selected tags.
- **Any of Tags (OR)** — matches conversations that have *at least one* of the selected tags.
- **Without Tags (Exclude)** — excludes conversations containing the specified tags.

### Disabling the Tags Display

If your workflow does not require tags, you can hide them from the chat interface:
- Open **Chat Settings** (the gear icon in the Chats header).
- Toggle the **"Show dialog tags"** setting (*"Dialog tags are specified in the bot settings and allow you to separate dialogs by business tasks"*).

---

## 4. Bot Constructor: "Chat Actions" Block

In the bot constructor, the **"Chat Actions"** block allows you to automatically adjust the conversation state as the user progresses through a bot flow.

Inside the block, enable the **"Manage Tags"** section:

### Adding Tags
- **Select from list**: pick one or more pre-configured bot tags.
- **From variable**: provide a variable containing an array of IDs `[1, 2, 3]` or a comma-separated string `1, 2, 3` (e.g. `{{selected_tags}}` or `{{ai_tags}}`).

### Removing Tags
- **Select from list**: check specific tags to remove from the conversation.
- **Clear entire category**: removes all tags belonging to a selected category (useful for resetting a funnel stage).
- **From variable**: remove tags by IDs provided in a variable.

### Unified System Message

When a bot flow executes a Chat Actions block, all triggered actions are combined into **a single consolidated system message** in the chat transcript, with each action printed on a new line:

```text
Manager John joined the conversation
Conversation added to folder "Hot Leads"
Bot auto-replies disabled
Tags added: VIP, Initial Consultation
Tag removed: New Lead
```

---

## 5. Automated AI Tagging and Classification

You can have an LLM / AI analyze user messages or dialogue context and dynamically assign matching tags.

The workflow consists of three steps:

```mermaid
graph LR
    A["Database Block<br>(Get Dialog Tags List)"] --> B["AI Integration / AI Dialog<br>(Classify & Output Tag IDs)"]
    B --> C["Chat Actions Block<br>(Assign Tags via Variable)"]
```

### Step 1. Fetch Tag List from Database

1. Add a **Database** block to your bot flow.
2. Select the **"Tags"** (or "Dialog Tags") source.
3. Select the **"Get tag list"** action.
4. *(Optional)* Select a specific tag category if you only want to classify within one group (e.g. *Services*).
5. Result variable name: defaults to `dialog_tags` (contains a JSON array of tags with their IDs and names).

### Step 2. AI Analysis & Classification

In the **AI Integration** block (or the system prompt of an **AI Dialog** node), pass the tag list variable and set a strict instruction for the output.

**Sample System Prompt:**

```text
You are a conversation classification assistant.
Here is the list of available tags in JSON format:
{{dialog_tags}}

Task:
Analyze the user's latest message and conversation history.
Select the matching tags from the list above.

Response format:
Return ONLY the numerical IDs of the selected tags separated by commas (e.g.: 3, 12).
If no tags match, return nothing (empty response).
Do NOT include any explanations, extra text, or punctuation other than numbers and commas.
```

Save the AI output to a variable, for example `{{ai_tags}}`.

### Step 3. Assign Tags in Chat Actions

1. Add a **Chat Actions** block following the AI step.
2. Enable **"Manage Tags"** → **"Add tags"**.
3. Set the mode to **"From variable"** and enter `{{ai_tags}}`.

The bot will automatically:
- Parse and validate the IDs from the variable.
- Assign the corresponding tags to the conversation (respecting single-selection category rules).
- Post a consolidated system message in the chat displaying the names of the assigned tags.
