Configuring Data Transfer from Live Chat to Bitrix24 CRM
Data from a chat reaches the CRM via three paths: through a native connector (if the chat has a ready-made integration), through the chat's webhook to the Bitrix24 REST API, or through the CRM's email channel. The choice depends on the chat platform and the required data completeness.
Method 1: Chat Webhook → crm.lead.add
Most chat platforms (JivoSite, Chatra, Talk-Me, LiveTex) support webhooks on conversation close. The handler on the site side receives the data and creates a lead:
// /local/api/chat-to-crm.php
require_once $_SERVER['DOCUMENT_ROOT'] . '/bitrix/modules/main/include/prolog_before.php';
$payload = json_decode(file_get_contents('php://input'), true);
if (!$payload) { http_response_code(400); exit; }
$name = trim($payload['visitor']['name'] ?? $payload['name'] ?? '');
$email = trim($payload['visitor']['email'] ?? $payload['email'] ?? '');
$phone = trim($payload['visitor']['phone'] ?? $payload['phone'] ?? '');
$text = buildTranscript($payload); // assemble the conversation transcript
// Basic validation: at least email or phone must be present
if (!$email && !$phone) {
http_response_code(200);
echo json_encode(['status' => 'skipped', 'reason' => 'no_contact_data']);
exit;
}
$leadId = createBitrix24Lead($name, $email, $phone, $text);
http_response_code(200);
echo json_encode(['status' => 'ok', 'lead_id' => $leadId]);
function createBitrix24Lead(string $name, string $email, string $phone, string $comments): int
{
$b24Url = rtrim(getenv('B24_WEBHOOK_URL'), '/') . '/';
$fields = [
'TITLE' => 'Chat: ' . ($name ?: $email ?: $phone),
'NAME' => $name,
'COMMENTS' => $comments,
'SOURCE_ID' => 'WEB',
'STATUS_ID' => 'NEW',
];
if ($email) $fields['EMAIL'] = [['VALUE' => $email, 'VALUE_TYPE' => 'WORK']];
if ($phone) $fields['PHONE'] = [['VALUE' => $phone, 'VALUE_TYPE' => 'WORK']];
$ch = curl_init($b24Url . 'crm.lead.add.json');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query(['fields' => $fields]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 10,
]);
$response = json_decode(curl_exec($ch), true);
curl_close($ch);
return (int)($response['result'] ?? 0);
}
Method 2: Bitrix24 Native Connector
JivoSite, LiveChat, and several other platforms have a ready-made connector in the Bitrix24 marketplace. Installation: Bitrix24 → Marketplace → find the required chat → Install. Authorize the connector in your chat account and configure which Open Channel receives the incoming inquiries.
Limitation of native connectors: data is passed in the format provided by the platform. Custom fields (such as 1C-Bitrix cart data) cannot be transferred through a native connector — only through a webhook with a custom handler.
Method 3: CRM Email Channel
The simplest option for chats without webhook support: configure the chat to send the transcript to an email address that Bitrix24 monitors as a CRM email channel. Bitrix24 identifies the contact by the email address in the message and creates a lead automatically.
Configuration: Bitrix24 → CRM → Settings → Mail Channels → Add Channel. Specify the mailbox that receives letters from the chat.
Passing Additional Data via UTM
To attribute a lead to a traffic source, include UTM parameters in the webhook:
// On the site side: read UTM parameters from the URL and store in sessionStorage
const params = new URLSearchParams(window.location.search);
['utm_source', 'utm_medium', 'utm_campaign'].forEach(k => {
if (params.get(k)) sessionStorage.setItem(k, params.get(k));
});
// In the webhook handler: retrieve UTM data from the chat payload
// (most chat platforms pass referrer and custom_data)
$utmSource = $payload['visitor']['utm_source'] ?? '';
$utmMedium = $payload['visitor']['utm_medium'] ?? '';
$utmCampaign = $payload['visitor']['utm_campaign'] ?? '';
$fields['UTM_SOURCE'] = $utmSource;
$fields['UTM_MEDIUM'] = $utmMedium;
$fields['UTM_CAMPAIGN'] = $utmCampaign;
Checking for Duplicates Before Creating a Lead
function leadExists(string $email, string $phone): bool
{
$b24Url = rtrim(getenv('B24_WEBHOOK_URL'), '/') . '/';
foreach (array_filter([$email, $phone]) as $value) {
$field = $email === $value ? 'EMAIL' : 'PHONE';
$response = callB24($b24Url . 'crm.lead.list.json', ['filter' => [$field => $value], 'select' => ['ID']]);
if (!empty($response['result'])) return true;
}
return false;
}
Timelines
| Method | Timeline |
|---|---|
| Native connector from marketplace | 2–4 hours |
| Webhook → crm.lead.add | 1–2 days |
| Webhook with deduplication and UTM | 2–3 days |







