# AI Copilot & Auto-Reply

OmnyBot integrates AI directly into Team Inbox to speed up responses, answer knowledge-base questions automatically, and help agents summarize threads or draft replies on demand.

:::note[Permissions & scope]
- **`inbox:reply`** is required to toggle AI per conversation, generate or send AI drafts, and chat with the internal AI Copilot.
- Configuring workspace-level AI settings, bots, and knowledge bases requires **`ai:manage`** or **`workspace:manage`**.
- AI auto-reply and drafts apply to **1-1 (`DIRECT`) conversations** across Zalo, Facebook, WhatsApp, and Webchat (disabled on group chats). AI usage draws from your workspace AI wallet token balance.
:::

## AI Draft Bar

The AI suggestion bar appears directly above the message composer:

- **Automatic Drafting on Inbound Messages**: when auto-drafting is enabled, OmnyBot uses a trailing **debounce** — waiting **6 seconds** after the customer's last message or typing signal (capped at **40 seconds** from the first message) so multi-message bursts are answered as a single turn.
- **On-Demand Drafting**: click **`+`** in the composer toolbar → **AI Draft** to generate a reply on demand for the current thread.
- **Draft Actions**:
  - **Send now**: sends the suggested reply immediately (including any attached media trigger album).
  - **Use**: loads the draft into the composer so you can edit it before sending.
  - **Regenerate**: asks the AI to draft an alternative response.
  - **Dismiss (`✕`)**: discards the current suggestion.

## Auto-Send (`AUTO_SEND`) & Human Handoff

Effective AI activation follows the hierarchy **Workspace → Channel / Bot → Conversation**.

In **`AUTO_SEND`** mode:

- The bot sends automatically only when the answer is strongly backed by the Knowledge Base, within the **active schedule** (Bot schedule first, falling back to the Workspace active window), and under the channel's **daily auto-send cap**.
- When a question falls outside the Knowledge Base, OmnyBot logs a **Knowledge Gap** (surfaced under **OmnyBot → AI**) and either degrades to a **Draft** or sends a configured **fallback message** (rate-limited to 1 per conversation per day by default).
- On **Zalo** in `AUTO_SEND` mode, short customer acknowledgements (such as "ok" or "thank you") may receive an automatic heart reaction (**❤️**) instead of an extra text message (capped at 120/day).

### Automatic Pause for Human Takeover

The bot automatically pauses on the current conversation when any of these conditions trigger (default pause duration is **4 hours**, configurable in Bot settings):

1. **Handoff Keywords**: the customer's message matches configured handoff keywords (defaults: `gặp nhân viên`, `gặp người thật`, `tư vấn viên`, `alo shop`, `hotline`). If a handoff fallback message is configured, the bot sends it before pausing.
2. **Consecutive Reply Limit**: the bot reaches the maximum consecutive replies allowed (default **3**) without human intervention.
3. **Out-of-KB Fallback**: when configured to send a fallback message with pause enabled (default `true`), the bot pauses so an agent can take over.

While paused, the bar above the composer shows a live countdown (**Bot paused • Resumes in ...**) with a **Resume Bot** button to reactivate immediately. Otherwise, the bot resumes automatically once the pause window expires.

## Per-Conversation AI Toggle

In the right sidebar under **Customer Profile → Info**, the **Auto-Reply** switch controls AI for that specific thread:

- **Off**: pauses automatic AI replies for this customer only (without affecting other threads on the channel).
- **On**: restores the thread to inherit the channel/bot AI configuration.

## Internal AI Copilot (Copilot Tab)

The **Copilot** tab in the right sidebar is an internal-only chat assistant — **customers never see** messages exchanged here.

Copilot automatically reads the customer's CRM profile (name, phone, lead status, tags, notes), the **last 30 messages**, and your workspace **Knowledge Base**:

- **4 Built-in Quick Prompts**:
  - Summarize this conversation
  - Suggest the next reply for the customer
  - Identify what product/service the customer is interested in
  - Draft a polite phone-number request and closing message
- **Using Suggested Replies**: whenever Copilot returns a suggested customer reply block, click **Copy** or **Insert into chat** to place it directly in the composer.
- **Session History**: Copilot chat history is kept in browser memory per conversation while you switch threads; click **Reset** to start a fresh Copilot session.