> For the complete documentation index, see [llms.txt](https://docs.a4b.vn/xbot/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.a4b.vn/xbot/features/understanding-the-message-handling-flow-1.md).

# Understanding the Message Handling Flow

The Message Handling Flow is a core component of xBot that dictates how incoming messages are processed, from initial receipt to the final response. This flow ensures that all user queries are accurately interpreted and handled, regardless of their complexity. By leveraging natural language processing (NLP) and predefined AI Flows, xBot can deliver timely and relevant responses across multiple communication channels.

In this guide, we'll explore how the message handling flow operates, how you can configure it, and best practices to optimize its performance.

<figure><img src="/files/V5hjyHepnUMwRTtbgecW" alt=""><figcaption><p>Message Handling Flow</p></figcaption></figure>

## Step-by-Step Process

### **1. Customer Sends a Message**

* A customer sends a message on a configured support channel(Zalo, Facebook, Teams, WebChat, Email).

### **2. Initial Processing by XBot**

* XBot checks if any additional customer information is needed and requests it if necessary.
* A conversation ID is assigned for tracking purposes.
* The message is then directed to the appropriate support group based on the configuration.

### **3. Dispatch Rule Routing**

* **Human Agent:**
  * If the message is routed to a human agent, the agent will chat directly with the customer and provide assistance.
* **AI Bot:**
  * **With AI Pre-Check:**
    * AI Pre-Check examines if the message contains negative content.
    * If the message is positive or neutral, it is forwarded to the AI agent to respond.
  * **Without AI Pre-Check:**
    * The message is directly sent to the AI agent without any pre-check.
  * **With AI Post-Check:**
    * After the AI agent responds, the response is sent for monitoring.
  * **Without AI Post-Check:**
    * The AI agent's response is sent directly to the customer without additional monitoring.
* **Manager:**
  * If the dispatch rule does not find a suitable agent or AI bot, the conversation is marked as unassigned.
  * Only the group manager can see and handle unassigned conversations.

### **4. Conversation Controls**

* **Enable/Disable AI Bot:**
  * If the conversation is assigned to an AI bot but the AI bot is disabled, the AI will not respond.
* **Enable/Disable Review:**
  * If review is enabled, all responses from the AI agent will wait for approval from a human agent before being sent to the customer.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.a4b.vn/xbot/features/understanding-the-message-handling-flow-1.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
