1C-Bitrix Integration with Chatra
Chatra is a live chat focused on simplicity and rapid deployment. Notable features include: an offline form instead of a closed widget, behavior-based auto-messages, and real-time typing preview. Integration with Bitrix is primarily about user identification and passing session data to the operator interface.
Installing the Chatra Code
<!-- In the Bitrix template, before </body> -->
<script>
(function(d, w, c) {
w.ChatraID = 'YOUR_CHATRA_ID';
var s = d.createElement('script');
w[c] = w[c] || function() { (w[c].q = w[c].q || []).push(arguments); };
s.async = true;
s.src = 'https://call.chatra.io/chatra.js';
if (d.head) d.head.appendChild(s);
}(document, window, 'Chatra'));
</script>
Identifying the Authenticated User
Chatra supports pre-identification via the ChatraSetup object:
<?php if ($USER->IsAuthorized()):
$userId = $USER->GetID();
$userEmail = $USER->GetEmail();
$userName = $USER->GetFullName();
?>
<script>
window.ChatraSetup = {
clientId: 'bitrix-user-<?= $userId ?>', // stable ID for chat history
};
Chatra('setIntegrationData', {
name: <?= json_encode($userName) ?>,
email: <?= json_encode($userEmail) ?>,
phone: <?= json_encode(getUserPhone($userId)) ?>,
'User ID': <?= $userId ?>,
'Orders': <?= getUserOrdersCount($userId) ?>,
'Total spent': <?= getUserTotalSpent($userId) ?> + ' USD',
});
</script>
<?php endif; ?>
clientId is a key parameter: with it, the conversation history is preserved across repeat visits by the same user. Without it, every session is an anonymous new conversation.
Automated Messages Based on Behavior
Chatra allows configuring auto-messages directly in the interface — by time on page, by section, by number of visits. For Bitrix-specific triggers (e.g., "user has been on the checkout page for more than 60 seconds"), JavaScript is required:
// If the user has been on checkout for longer than 60 seconds
<?php if (strpos($_SERVER['REQUEST_URI'], 'order') !== false): ?>
<script>
setTimeout(function() {
Chatra('sendAutoMessage', 'Need help placing your order? I\'m happy to assist.');
}, 60000);
</script>
<?php endif; ?>
sendAutoMessage is only available on the Chatra Full Suite plan.
Passing Cart Data
<?php
\Bitrix\Main\Loader::includeModule('sale');
$basket = \Bitrix\Sale\Basket::loadItemsForFUser(\Bitrix\Sale\Fuser::getId(), SITE_ID);
$basketTotal = $basket->getPrice();
$basketCount = count($basket);
?>
<script>
Chatra('setIntegrationData', {
'Cart total': <?= $basketTotal ?> + ' USD',
'Cart items': <?= $basketCount ?>,
});
</script>
Chatra Webhook: Creating Leads in Bitrix
Chatra sends a webhook when a conversation closes (Full Suite plan). Setup: Dashboard → Settings → Integrations → Webhooks.
// /local/api/chatra-webhook.php
$payload = json_decode(file_get_contents('php://input'), true);
if (isset($payload['trigger']) && $payload['trigger'] === 'chat.done') {
$chat = $payload['chat'];
$visitor = $payload['visitor'];
$transcript = '';
foreach ($chat['messages'] as $msg) {
$transcript .= "[{$msg['authorName']}]: {$msg['text']}\n";
}
// Create a task or lead in Bitrix24
$leadTitle = 'Chatra: ' . ($visitor['name'] ?? $visitor['email'] ?? 'Guest');
createBitrix24Lead([
'TITLE' => $leadTitle,
'NAME' => $visitor['name'] ?? '',
'EMAIL' => $visitor['email'] ?? '',
'PHONE' => $visitor['phone'] ?? '',
'COMMENTS' => $transcript,
'SOURCE_DESCRIPTION' => 'Chatra #' . $chat['id'],
]);
}
http_response_code(200);
Disabling the Widget on Service Pages
In Bitrix there are pages where a chat widget is undesirable: the admin area /bitrix/admin/, the payment redirect page, the error page. Restrict loading in the template:
<?php
$excludePaths = ['/bitrix/', '/local/ajax/', '/api/'];
$showChatra = true;
foreach ($excludePaths as $path) {
if (strpos($_SERVER['REQUEST_URI'], $path) === 0) {
$showChatra = false;
break;
}
}
if ($showChatra):
?>
<!-- Chatra code here -->
<?php endif; ?>
Scope of work: installation and user identification — 4–8 hours. Cart data and page context — another half day. Webhook and CRM integration — 1 day. Total timeline — 2–3 business days including testing.







