Developing a Facebook Messenger Bot with Bitrix24 Integration

Developing a Facebook Messenger Bot with Bitrix24 Integration When you launch a Facebook ad campaign, you receive dozens of leads in Messenger, but managers spend time manually qualifying and entering data into the CRM? We've faced this many times. Our solution is a bot that automatically receive

Our competencies:

Frequently Asked Questions

Latest works

  • image_website-b2b-advance_0.webp
    B2B ADVANCE company website development
    1415
  • image_bitrix-bitrix-24-1c_fixper_448_0.webp
    Website development for FIXPER company
    995
  • 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
    733
  • image_bitrix-bitrix-24-1c_mirsanbel_458_0.webp
    Development based on 1C Enterprise for MIRSANBEL
    863
  • image_crm_dolbimby_434_0.webp
    Website development on CRM Bitrix24 for DOLBIMBY
    772
  • image_crm_technotorgcomplex_453_0.webp
    Development based on Bitrix24 for the company TECHNOTORGKOMPLEKS
    1134

Developing a Facebook Messenger Bot with Bitrix24 Integration

When you launch a Facebook ad campaign, you receive dozens of leads in Messenger, but managers spend time manually qualifying and entering data into the CRM? We've faced this many times. Our solution is a bot that automatically receives messages, asks clarifying questions according to a scenario, creates a lead in Bitrix24, and transfers the conversation to an operator when needed. The integration is done turnkey: from setting up a Meta App to production launch. Automating the first touch reduces response time by 80% — this is confirmed by Messenger Platform Documentation. Managers save up to 70% of time, and average savings per lead reduce ad costs by up to 30%.

Why Messenger Automation Matters

Customers expect instant responses. A bot processes leads 10 times faster than manual data entry, while eliminating human error. Every lead immediately enters the CRM with the full dialog history. The operator sees the context and can join at any moment. This increases sales conversion by 25–40% based on our projects. With an average ad budget, integration pays for itself in 2–3 months.

How the Integration Works

A customer writes to a Facebook page. A Meta webhook sends a POST request to our server. The server processes the text, determines intent, and replies via the Messenger Send API. Simultaneously, a lead is created and an activity is logged via the Bitrix24 REST API. If the customer requests operator assistance, the bot invokes the Handoff Protocol — and the manager takes over directly from the CRM card. The whole process takes seconds.

Technical Requirements

Meta provides the Messenger Platform API for automation. Requirements: a Facebook Developer App with the Messenger product, a Facebook page, and a PAGE_ACCESS_TOKEN. Webhook verification is mandatory — a GET request with hub.verify_token and hub.challenge. The server returns the challenge if the token matches.

Incoming messages arrive as POST with JSON body: {"entry":[{"messaging":[{"sender":{"id":"123"},"message":{"text":"example"}}]}]}. Meta expects a 200 OK response within 5 seconds — heavy processing is offloaded to a queue.

Sending messages with quick replies:

function sendMessengerMessage(string $psid, string $text, array $quickReplies = []): void { $payload = [ 'recipient' => ['id' => $psid], 'message' => ['text' => $text], ]; if ($quickReplies) { $payload['message']['quick_replies'] = $quickReplies; } $ch = curl_init("https://graph.facebook.com/v18.0/me/messages?access_token=" . PAGE_ACCESS_TOKEN); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_exec($ch); } $quickReplies = [ ['content_type' => 'text', 'title' => 'Yes, interested', 'payload' => 'INTERESTED'], ['content_type' => 'text', 'title' => 'Just browsing', 'payload' => 'BROWSING'], ]; sendMessengerMessage($psid, 'Help you choose?', $quickReplies); 

Generic Template for product cards:

$template = [ 'recipient' => ['id' => $psid], 'message' => [ 'attachment' => [ 'type' => 'template', 'payload' => [ 'template_type' => 'generic', 'elements' => [[ 'title' => $productName, 'image_url' => $productImage, 'subtitle' => $productDescription, 'buttons' => [ ['type' => 'web_url', 'url' => $productUrl, 'title' => 'Details'], ['type' => 'postback', 'title' => 'Order', 'payload' => "ORDER_{$productId}"], ], ]], ], ], ], ]; 

Creating Leads and Activities in Bitrix24

$leadId = $b24->callMethod('crm.lead.add', [ 'fields' => [ 'TITLE' => "Messenger: {$firstName} {$lastName}", 'NAME' => $firstName, 'LAST_NAME' => $lastName, 'SOURCE_ID' => 'WEBFORM', 'SOURCE_DESCRIPTION' => 'Facebook Messenger', 'UF_CRM_FB_PSID' => $psid, 'COMMENTS' => "Facebook Profile ID: {$psid}", ], ])['result']; $b24->callMethod('crm.activity.add', [ 'fields' => [ 'OWNER_TYPE_ID' => 1, 'OWNER_ID' => $leadId, 'TYPE_ID' => 4, 'SUBJECT' => 'Facebook Messenger Message', 'DESCRIPTION' => "{$firstName}: {$messageText}", 'DEADLINE' => date('Y-m-d\TH:i:s'), ], ]); 

What's Included in the Work

Component Description
Meta App and webhook setup Creating the app, generating tokens, verification
Dialog scenario development States, quick replies, carousels, fallback messages
Bitrix24 integration Lead creation, activity logging, field updates
Meta App review Privacy policy preparation, passing moderation
Documentation and training Instructions for operators, handoff scheme
Stability guarantee Monitoring, message queue, error handling

How to Set Up the Integration in 5 Steps

  1. Create a Facebook Developer App and add the Messenger product.
  2. Configure the webhook to your server, provide URL and verify token.
  3. Develop the dialog scenario: define states, quick replies, fallback messages.
  4. Implement Bitrix24 integration via REST API: lead creation and activity logging.
  5. Test all scenarios and pass Meta App review.

Timeline and Budget

Stage Duration
Meta App setup, webhook, verification 1–2 days
Bot scenario, states, quick replies 3–4 days
Bitrix24 integration: leads, activities 2–3 days
Message templates, Generic Templates 1–2 days
Operator handoff 1–2 days
Testing + Meta App review 2–4 days

Total: 2–3 weeks including Meta review. Cost is calculated individually based on scenario complexity and number of integrations. Project payback averages 2–3 months through resource savings. Get a project estimate — contact us for a calculation.

Common Mistakes and How to Avoid Them

  • Lack of message queue. Under high load, Meta retries requests — without a queue you risk duplicate leads. We use queues (RabbitMQ or Redis).
  • Incorrect Handoff. Without pass_thread_control, the conversation isn't transferred to the operator. We verify correct invocation during testing.
  • Skipping Meta review. The app will be blocked without approved permissions. We prepare privacy policy and go through review in advance.
  • Ignoring the 24-hour window. After the window expires, only templates can be sent — we configure automatic sending of approved Message Tags.

Our experience with over 10 Messenger + Bitrix24 integrations guarantees stable operation under load. Certified Bitrix24 specialists ensure compliance with platform requirements. Order a consultation — we'll show how the bot can work for your business. We guarantee transparency and support after launch.

Meta App Review: Requirements and Risks

Meta requires mandatory review before publication. We prepare all documents: privacy policy, icons, description. During development, we avoid using unapproved templates and spam patterns. After passing review, the bot runs stably without risk of blocking.