Developing a bot for processing requests from the 1C-Bitrix website

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

Development of Form Request Processing Bot for 1C-Bitrix

Request submitted on site — then silence. Manager might notice it an hour later, a day later, or not at all. A processing bot closes this gap: instantly captures the request in Bitrix24, notifies responsible manager, sends auto-reply to client, optionally starts dialog in messenger.

Entry Point: 1C-Bitrix Form Events

All site forms — CWebForm, web-forms from form module, callback orders from sale.order.ajax, custom AJAX forms — generate submission events. We intercept needed ones:

Web-form module forms:

// local/php_interface/init.php
AddEventHandler('form', 'OnAfterResultAdd', 'handleFormSubmit');

function handleFormSubmit(int $webFormId, int $resultId, array $arResult): void {
    if (!in_array($webFormId, [1, 3, 7])) { // IDs of needed forms
        return;
    }
    // Push to queue or process synchronously
    BotQueue::push('process_form', [
        'form_id'   => $webFormId,
        'result_id' => $resultId,
        'fields'    => $arResult,
    ]);
}

bitrix:main.feedback component: For callback orders (sale.order.callback) — own handler via OnSaleOrderCallbackCreate event.

Creating Lead/Deal in Bitrix24

After getting form data, create CRM entity. Selection logic: if request is qualified (has phone, interest clear) — straight deal; if first contact — lead.

// Lead creation
$leadId = $b24Rest->callMethod('crm.lead.add', [
    'fields' => [
        'TITLE'          => "Request from site: {$formName}",
        'NAME'           => $arResult['NAME'] ?? '',
        'LAST_NAME'      => $arResult['LAST_NAME'] ?? '',
        'PHONE'          => [['VALUE' => $arResult['PHONE'], 'VALUE_TYPE' => 'WORK']],
        'EMAIL'          => [['VALUE' => $arResult['EMAIL'], 'VALUE_TYPE' => 'WORK']],
        'SOURCE_ID'      => 'WEB',
        'SOURCE_DESCRIPTION' => $formName,
        'COMMENTS'       => $arResult['COMMENT'] ?? '',
        'ASSIGNED_BY_ID' => getResponsibleManager($webFormId),
        'UTM_SOURCE'     => $_COOKIE['utm_source'] ?? '',
        'UTM_MEDIUM'     => $_COOKIE['utm_medium'] ?? '',
        'UTM_CAMPAIGN'   => $_COOKIE['utm_campaign'] ?? '',
    ],
])['result'];

UTM tags pulled from cookies — important for source analytics.

Manager Notification via Bot

After lead creation, bot writes to responsible in Bitrix24:

$b24Rest->callMethod('imbot.message.add', [
    'BOT_ID'    => $botId,
    'DIALOG_ID' => 'u' . $managerId,
    'MESSAGE'   => "[b]New site request[/b]",
    'ATTACH'    => [[
        'TITLE'       => $formName,
        'DESCRIPTION' => "Client: {$name}\nPhone: {$phone}\nComment: {$comment}",
        'COLOR'       => '#2fc6f6',
        'LINK'        => "https://b24.company.ru/crm/lead/show/{$leadId}/",
    ]],
    'KEYBOARD'  => ['BUTTONS' => [[
        ['TEXT' => 'Open lead',     'LINK'    => "https://b24.company.ru/crm/lead/show/{$leadId}/"],
        ['TEXT' => 'Take to work',  'COMMAND' => 'assign_lead', 'COMMAND_PARAMS' => $leadId],
    ]]],
]);

Auto-Reply to Client

Client gets confirmation via email and/or SMS:

// Email via Bitrix
\Bitrix\Main\Mail\Event::sendImmediate([
    'EVENT_NAME'  => 'FORM_SUBMIT_CONFIRM',
    'LID'         => SITE_ID,
    'C_FIELDS'    => [
        'CLIENT_NAME'  => $name,
        'CLIENT_EMAIL' => $email,
        'FORM_NAME'    => $formName,
        'LEAD_URL'     => '',
    ],
    'TO_EMAIL'    => $email,
]);

If client has Telegram — bot can message there if Telegram channel integration set up.

Request Routing by Type

Different forms → different responsible:

function getResponsibleManager(int $formId): int {
    $routing = [
        1 => 15,  // "Consultation" form → Ivan
        3 => 22,  // "Partnership" form → Peter
        7 => 8,   // "Support" form → Simon
    ];
    return $routing[$formId] ?? 1; // default manager
}

For complex routing (by time of day, manager load, client region) — logic becomes more complex, but principle same.

Handling Duplicate Requests

Before creating new lead, check for existing open lead with same phone:

$existing = $b24Rest->callMethod('crm.lead.list', [
    'filter' => [
        'PHONE' => $phone,
        '!STATUS_ID' => ['CONVERTED', 'LOSE'],
    ],
    'select' => ['ID', 'TITLE', 'ASSIGNED_BY_ID'],
])['result'];

if ($existing) {
    // Add activity to existing lead instead of creating new
    addActivityToLead($existing[0]['ID'], $comment);
    notifyManager($existing[0]['ASSIGNED_BY_ID'], "Duplicate request on lead #{$existing[0]['ID']}");
    return;
}

Queue for Reliability

With high traffic, form handler shouldn't slow response. Queue architecture:

  1. OnAfterResultAdd puts task in Redis queue (< 1 ms).
  2. Worker (PHP daemon or cron every minute) picks tasks and processes.
  3. If B24 REST API unavailable — task stays in queue, processed next iteration.

Timeline

Stage Duration
Intercept Bitrix form events 1–2 days
Lead creation in B24, routing 2–3 days
Bot notifications, action buttons 2–3 days
Auto-reply to client (email/SMS) 1–2 days
Duplicate handling, repeat requests 1–2 days
Queue + testing 1–2 days

Total: 1.5–2 weeks for standard site form set.