Integration of an online consultant with CRM Bitrix24

Our company is engaged in the development, support and maintenance of Bitrix and Bitrix24 solutions of any complexity. From simple one-page sites to complex online stores, CRM systems with 1C and telephony integration. The experience of developers is confirmed by certificates from the vendor.
Our competencies:
Development stages
Latest works
  • image_website-b2b-advance_0.png
    B2B ADVANCE company website development
    1175
  • image_bitrix-bitrix-24-1c_fixper_448_0.png
    Website development for FIXPER company
    811
  • image_bitrix-bitrix-24-1c_development_of_an_online_appointment_booking_widget_for_a_medical_center_594_0.webp
    Development based on Bitrix, Bitrix24, 1C for the company Development of an Online Appointment Booking Widget for a Medical Center
    564
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    747
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    655
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    976

Integrating a Live Chat with Bitrix24 CRM

A live chat without a CRM is simply a communication tool. With a CRM, it becomes a lead source, contact history, and a deal pipeline. The gap between chat and CRM costs money: a manager closes a conversation, the data is saved nowhere, and a week later the client calls again and has to start from scratch. Integration eliminates this.

Integration Architecture

There are several ways to connect a live chat to Bitrix24 CRM, and the choice depends on the chat platform:

Native integrations. Some chat platforms (JivoSite, LiveChat, Callibri) have ready-made connectors for Bitrix24 — available via the Bitrix24 marketplace or directly within the chat's settings. This is the fastest path, but with limited customization options.

Bitrix24 Open Channels. A mechanism that allows an external chat channel to be connected to Bitrix24 CRM. Messages from the chat appear in the Open Channels interface, the operator responds from Bitrix24, and the reply is delivered to the client in the on-site chat. Requires webhook implementation in both directions.

Bitrix24 REST API + chat webhook. The chat sends a webhook upon conversation close; the handler creates a lead/contact/deal via crm.lead.add or crm.contact.add.

Integration via Open Channels

Open Channels is the most deeply integrated option. It requires building a custom connector.

Step 1. Register the connector in Bitrix24:

// Register the external channel via REST API
$result = callBitrix24Rest('imopenlines.connector.register', [
    'ID'          => 'my_chat_connector',
    'NAME'        => 'Website Live Chat',
    'ICON_FILE'   => 'https://yoursite.ru/icon.png',
    'ENDPOINT'    => 'https://yoursite.ru/local/api/chat-send.php',
    'HANDLER'     => 'https://yoursite.ru/local/api/chat-handler.php',
]);

Step 2. Forward a message from the chat to Bitrix24:

// When a client sends a message in the on-site chat
function sendMessageToBitrix24(string $userId, string $message, string $userName): void
{
    callBitrix24Rest('imopenlines.message.add', [
        'CONNECTOR' => 'my_chat_connector',
        'LINE'      => OPENLINE_ID,
        'MESSAGES'  => [[
            'user' => [
                'id'     => 'chat-user-' . $userId,
                'name'   => $userName,
                'avatar' => '',
            ],
            'message' => ['text' => $message],
            'timestamp' => time(),
        ]],
    ]);
}

Step 3. Receive the operator's reply from Bitrix24:

Bitrix24 calls ENDPOINT when the operator responds:

// /local/api/chat-send.php
$payload = json_decode(file_get_contents('php://input'), true);

$chatUserId = $payload['data']['USER']['ID'];    // 'chat-user-{id}'
$message    = $payload['data']['MESSAGES'][0]['text'];

// Forward the reply to the on-site chat via your chat service API
ChatService::sendToUser(extractUserId($chatUserId), $message);

http_response_code(200);
echo json_encode(['RESULT' => 'OK']);

Creating a Lead via REST API on Conversation Close

If Open Channels is overkill, simply creating a lead when the chat closes is sufficient:

function createLeadFromChat(array $visitorData, string $transcript): int
{
    $response = callBitrix24Rest('crm.lead.add', [
        'fields' => [
            'TITLE'       => 'Chat: ' . ($visitorData['name'] ?: $visitorData['email'] ?: 'Guest'),
            'NAME'        => $visitorData['name']  ?? '',
            'EMAIL'       => [['VALUE' => $visitorData['email'] ?? '', 'VALUE_TYPE' => 'WORK']],
            'PHONE'       => [['VALUE' => $visitorData['phone'] ?? '', 'VALUE_TYPE' => 'WORK']],
            'COMMENTS'    => htmlspecialchars($transcript),
            'SOURCE_ID'   => 'WEB',
            'STATUS_ID'   => 'NEW',
            'ASSIGNED_BY_ID' => getResponsibleManagerId(),
        ],
        'params' => ['REGISTER_SONET_EVENT' => 'N'],
    ]);

    return (int)($response['result'] ?? 0);
}

Deduplication: Avoiding Duplicate Contacts

Before creating a lead, check whether a contact with the given email or phone number already exists:

function findExistingContact(string $email, string $phone): ?int
{
    // Search by email
    if ($email) {
        $result = callBitrix24Rest('crm.contact.list', [
            'filter' => ['EMAIL' => $email],
            'select' => ['ID'],
        ]);
        if (!empty($result['result'][0]['ID'])) return (int)$result['result'][0]['ID'];
    }

    // Search by phone
    if ($phone) {
        $result = callBitrix24Rest('crm.contact.list', [
            'filter' => ['PHONE' => $phone],
            'select' => ['ID'],
        ]);
        if (!empty($result['result'][0]['ID'])) return (int)$result['result'][0]['ID'];
    }

    return null;
}

// If an existing contact is found — create a deal, not a lead
$contactId = findExistingContact($email, $phone);
if ($contactId) {
    callBitrix24Rest('crm.deal.add', [
        'fields' => [
            'TITLE'       => 'Chat inquiry',
            'CONTACT_ID'  => $contactId,
            'COMMENTS'    => $transcript,
            'SOURCE_ID'   => 'WEB',
        ],
    ]);
} else {
    createLeadFromChat($visitorData, $transcript);
}

Assigning a Responsible Manager

To automatically assign a responsible manager to a lead/deal from chat, use source-based logic:

function getResponsibleManagerId(): int
{
    // Round-robin rotation, time-of-day assignment,
    // or a fixed manager for chat leads
    $managers = [15, 23, 41]; // Bitrix24 user IDs
    return $managers[array_rand($managers)];
}

Notifying the Assigned Manager

After creating the lead, send a notification in Bitrix24:

callBitrix24Rest('im.notify.system.add', [
    'USER_ID' => $responsibleId,
    'MESSAGE' => 'New chat inquiry. Lead #' . $leadId . ' created.',
]);

Scope of Work

  • Selecting the integration architecture (Open Channels or Webhook → lead)
  • Developing the webhook handler on the Bitrix side
  • Contact deduplication logic
  • Assigning responsible managers, notifications
  • Testing all scenarios: new client, returning client, incomplete contact data

Timelines: webhook integration with lead creation — 2–3 days. Full integration via Open Channels — 2–3 weeks.