> ## Documentation Index
> Fetch the complete documentation index at: https://docs.talqui.chat/llms.txt
> Use this file to discover all available pages before exploring further.

# Message Processing

## Overview

The Chatbot Builder processes incoming messages through a structured flow-based system where each conversation follows a predefined path composed of interconnected blocks (neurons). When a message arrives, the system first checks whether this is the first message of the session with the virtual agent. If it is the first message, processing begins at the entry point—the initial non-editable block of the Bot Builder, which serves as the starting point where all conversations originate. If it is not the first message, the system resumes from where the conversation previously paused, continuing from the last processed block.

Once the starting point is determined, the system evaluates the current block to determine its type: a simple send block or a send block with response reception (requiring user input). Blocks can have two stages: a send stage and a receive stage. Both stages may include message preparation phases that involve external API calls, such as integrations with CRM systems like SGP and IXC. For example, the system might send a request to the CRM to identify contracts for a user, receive the API response, prepare a message based on that response, send it to the user, and then wait for the user to select which account they want to proceed with.

After sending a message to the user, the system may or may not wait for user input, depending on whether the block has a reception element. If the block includes reception and the user provides input, the flow is triggered again from the point where the conversation paused. The system recognizes this as a response and processes the response block, finalizing it based on the conditions met. Depending on the condition reached, the block may have multiple outputs, and the system selects the appropriate output to proceed to the next neuron, effectively restarting the entire process with validation stages. This cycle continues until the conversation reaches an endpoint or completes its intended flow.

## Message Processing Flow

The following sequence diagram illustrates the complete message processing flow: [click here to open in a new tab](https://kroki.io/mermaid/svg/eNrNVU1v2zAMve9X8JgAbVMUDTAUQ4AtbYceUgTNNuyq2IwrTJFciU6b_fpRcvyh2GmzYofl4MgW-cRH8lEOnwrUCV5LkVmx_gD8y4UlmchcaILvDm3n42LrCLu2t8o8z4QWWY_LF2WSX3NrEnTOdLdvXgitFurz_A6Eq1_Bvw-mD7PR4ut89HM67DjOGI8PXKBO-dSw7UM-nUzKIK_AbzlYl3bBoNxhk1bAV_CACcoNRpbhIRRTk9ZRtQVmBY6X0uhg4H8tqH3guxQ1ydXWE1u1cQ44x6liAsR8YWXNGhjIbiE3UtOnpR1NBlJLkpwnbfQpppLEUiEsPUCZKlQO4d7QUQf3R40v0pHUGSRGb9A6QYd574f-gK5YYxm7EhxACK2MTKdNimO_HqCbjVCFoB03oG2OZQKcXOdM2TEcGFv-P0t6BMvlzH2ow-YY_kZgs-Xg4vL8BC4uP_JjPB7WZLThEwyThE4NPC4Xgou_-8oZqf3eDH_6iBy1XNUdlFvkLg6pBI2YYlqD1Qvfd5EQEqEUc3gqpG3Z9wbQ0tMueO-HXIEBnmVnJ5AhQcFC8VUlKxJywwixBXDaW1gqrGZQlxvNLZYKEq9HtI8wDxmo5QZL4ZBLqAPTCreGrLolSlDnjGgY7HhX-GQC39o5smVfPzWu4BqV9PVvCyXqVF-UcC48spzrJmOh4ZoFU8PvDSGOciNTdCB1XtCow69_JH2zMuMFrPhjKaJcFD5NYQIcqcHdsqlVo8Eom404xuNKHJfncVccFkg1PQ9q5Kim-CGUTL3MQ2uGXP0dQD0nuK15HHJlXAQQvbwuMFjxPOkU6h2KC-PoAKF_IbUj5bbXBR2YtsQ6qXoT_1YyA_kbmwPyd_bAgqXEnWgK4mQ1Y6GnoMcNhUhRM25ePwo0vhA_Cnv0VVYlMHjGEro_qIrpNlE-JTkKcs2FXA4Q6SC6vbTa_s8s_EUhNXd0NRT_AJMfQQE)

```mermaid theme={null}
sequenceDiagram
    participant User
    participant System
    participant FlowManager
    participant BlockProcessor
    participant ExternalAPI as External API (CRM/SGP/XC)
    participant MessageSender

    User->>System: Sends message
    System->>FlowManager: Receive message
    
    alt First message of session
        FlowManager->>FlowManager: Identify as first message
        FlowManager->>BlockProcessor: Start from entry point<br/>(initial non-editable block)
    else Not first message
        FlowManager->>FlowManager: Identify existing conversation
        FlowManager->>BlockProcessor: Resume from last block
    end
    
    BlockProcessor->>BlockProcessor: Evaluate block type<br/>(simple send or send with reception)
    
    rect rgb(240, 248, 255)
        note over BlockProcessor: Send Stage Processing
        BlockProcessor->>BlockProcessor: Check if message preparation needed
        
        alt External API call required
            BlockProcessor->>ExternalAPI: Send request (e.g., get user contracts)
            ExternalAPI-->>BlockProcessor: Return response data
            BlockProcessor->>BlockProcessor: Prepare message based on API response
        end
        
        BlockProcessor->>MessageSender: Send message to user
        MessageSender->>User: Deliver message
    end
    
    alt Block has reception element
        User->>System: Provides input/response
        System->>FlowManager: Trigger flow from paused point
        FlowManager->>BlockProcessor: Process response block
        
        rect rgb(255, 248, 240)
            note over BlockProcessor: Receive Stage Processing
            BlockProcessor->>BlockProcessor: Validate user input
            BlockProcessor->>BlockProcessor: Evaluate conditions
            
            alt External API call required for response
                BlockProcessor->>ExternalAPI: Send request with user input
                ExternalAPI-->>BlockProcessor: Return response data
                BlockProcessor->>BlockProcessor: Process response data
            end
            
            BlockProcessor->>BlockProcessor: Finalize response processing
            BlockProcessor->>BlockProcessor: Select output based on conditions
        end
        
        BlockProcessor->>FlowManager: Move to next neuron
        FlowManager->>BlockProcessor: Process next block
        Note over BlockProcessor: Cycle repeats
    else Block is simple send only
        BlockProcessor->>FlowManager: Move to next neuron
        FlowManager->>BlockProcessor: Process next block
        Note over BlockProcessor: Cycle continues
    end
```

During message processing, the Chatbot Builder maintains conversation state, which includes variables, user data, and the current position in the flow. This state persists across multiple message exchanges, allowing the chatbot to remember context, track progress through multi-step processes, and make decisions based on previous interactions. The system also handles error scenarios gracefully, routing conversations to error handling blocks when API calls fail, when validation errors occur, or when unexpected conditions are encountered, ensuring that users always receive appropriate responses even when something goes wrong.

Developers can extend the Chatbot Builder's functionality by integrating with their own APIs. API integrations support two different integration methods, each suited for different use cases and requirements. For detailed information about neuron types and integration methods, refer to the [Neurons documentation](/guides/bot-builder/neurons).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.