Integrating Bitrix24 with FreePBX

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
    1173
  • 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
    745
  • 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

Bitrix24 Integration with FreePBX

FreePBX is a graphical management interface on top of Asterisk. Most companies that "have Asterisk" are actually running FreePBX: it simplifies configuration through a web panel, manages extensions, queues, and IVR without manual config file editing. Technically, the integration with Bitrix24 is built the same way as with Asterisk, but FreePBX adds its own toolset — modules, AGI integrations, and the FreePBX API.

FreePBX API and the Asterisk-CRM integration module

FreePBX has its own REST API (FreePBX RESTAPI), available from version 14+. This allows managing extensions, queues, and configuration via HTTP requests, which is convenient for automation. However, for Bitrix24 integration, the Asterisk AMI is more important — the same interface as in plain Asterisk.

Three approaches can be used on FreePBX:

1. AGI script. An AGI script call is added to the FreePBX dial plan in the required contexts. The script receives call variables and transfers data to Bitrix24.

2. AMI daemon. A separate process listens to AMI and handles events — analogous to the integration with plain Asterisk.

3. Bitrix24 module for FreePBX — a commercial or open-source module installed through the FreePBX administrative panel (Admin → Module Admin). Some modules are available in the FreePBX repository, others are supplied separately.

AGI integration configuration

AGI (Asterisk Gateway Interface) is the protocol for interaction between the Asterisk dial plan and external scripts. In FreePBX, the dial plan is managed through the web interface, and adding an AGI call is done via a custom context.

In Admin → Config Edit (or via the file /etc/asterisk/extensions_custom.conf), add to the required context:

[from-internal-custom]
exten => _.,1,AGI(bitriks24.php,${EXTEN},${CALLERID(num)},${UNIQUEID})
exten => _.,n,Return()

The script /var/lib/asterisk/agi-bin/bitriks24.php receives three arguments: destination number, caller number, unique ID. Inside the script — a Bitrix24 REST API call to register the call.

For inbound calls, the context will be from-trunk-custom or equivalent depending on the FreePBX configuration.

FreePBX queues and mapping to Bitrix24 departments

FreePBX has a well-developed queue module. Typical scheme: an inbound call enters IVR, the client selects a department — the call goes to the corresponding queue.

When integrating with Bitrix24, it is necessary to know which FreePBX queue the call landed in, in order to link it to the correct department in CRM. In AMI events this is visible via the channel variable QUEUE_NAME. It is passed to Bitrix24 via the LINE_NUMBER parameter when registering the call — this allows Bitrix24 to route the call to the appropriate responsible parties.

FreePBX queue Bitrix24 parameter Responsible in CRM
sales LINE_NUMBER=200 Sales department
support LINE_NUMBER=201 Technical support
billing LINE_NUMBER=202 Finance department

Call recording: FreePBX configuration

FreePBX manages recording via the Call Recording module. In the extension or queue settings, recording is enabled (Record Calls: Always). Files are saved in /var/spool/asterisk/monitor/ with the naming format YYYYMMDD-HHMMSS-CALLERID-EXTEN-UNIQUEID.wav.

After a call is processed, the AMI daemon or AGI script looks up the file by UNIQUEID and transfers it to Bitrix24. It is critical to wait for the recording conversion to complete (FreePBX automatically converts .wav to .mp3 if configured via cron). Conversion time depends on the call duration.

Case study: law firm with multi-level IVR

The company used FreePBX 15 with a 6-department IVR, each with its own queue. Requirement: in Bitrix24, a call must be created not at the moment the IVR starts, but only after the client has selected a department and been placed in a queue. Otherwise, short "technical" calls from clients who hung up while listening to the menu would be recorded.

Solution: the AGI script runs in the queue context (after the IVR selection), not in the inbound trunk context. telephony.externalcall.register is called only when the call actually enters a queue. Additionally: if a client hung up while waiting in the queue without an answer — a missed call and a lead are created with the tag "Did not wait in queue", which triggers an auto-callback via Bitrix24 robots.

Setup timeframe: 4–6 business days.