Bitrix24 and Asterisk Integration: AMI, Call Recordings, CRM

We often hear from companies: 'We already have Asterisk, everything is configured, ten operators, a hundred calls a day. Now we've taken Bitrix24 — how do we connect without redoing the telephony?' Good news: you won't have to throw away Asterisk. Integration via AMI or SIP trunk allows you to keep

Our competencies:

Frequently Asked Questions

We often hear from companies: 'We already have Asterisk, everything is configured, ten operators, a hundred calls a day. Now we've taken Bitrix24 — how do we connect without redoing the telephony?' Good news: you won't have to throw away Asterisk. Integration via AMI or SIP trunk allows you to keep your existing PBX and get all CRM features: pop-up call card, automatic lead creation, call recording. Over 5 years we've set up such connections for dozens of clients — from startups to companies with call centers of 50 operators. Equipment savings with this approach reach 30%.

How to Integrate Bitrix24 with Asterisk Without Losing Flexibility?

There are two main architectural approaches: SIP trunk and AMI/AGI-integration. The choice depends on whether you want to move the media stream to the cloud or keep routing on Asterisk.

What Does AMI-Integration Provide Compared to SIP Trunk?

SIP trunk — Asterisk registers as a SIP trunk in the Bitrix24 cloud PBX. All voice passes through Bitrix24 servers, adding latency. AMI integration (via Asterisk Manager Interface) transmits only events: call started, ended, duration. The media stream stays local — sound quality does not degrade. For companies with an already configured provider, AMI is the optimal choice. AMI establishes connections 2 times faster than SIP trunk.

Characteristic SIP trunk AMI integration
Routing In Asterisk or in the cloud Only in Asterisk
Latency + (through Bitrix24 servers) Minimal (local)
Setup complexity Medium, requires SIP config Higher, requires AMI daemon
IVR/queue flexibility Limited by cloud PBX capabilities Full, Asterisk
Call recording Automatically in Bitrix24 Via API, with file attachment
Performance Lower due to extra hop Higher, media does not leave local network

According to Asterisk documentation, AMI provides management via TCP connection.

Setting Up AMI Integration: Step-by-Step Instructions

Let's deploy a typical scheme:

  1. Create an AMI user in /etc/asterisk/manager.conf:

    [bitriks_agi] secret = your_secret_password read = call,cdr write = originate permit = 127.0.0.1/255.255.255.0 

    Run a daemon (on Node.js, PHP, or Python) that listens to AMI events:

    • Newchannel — incoming call
    • Hangup — termination
    • Bridge — operator answered

    On Newchannel, call the Bitrix24 REST API:

    POST /rest/telephony.externalcall.register { "USER_PHONE_INNER": "101", "USER_ID": 5, "PHONE_NUMBER": "+74951234567", "CALL_START_DATE": "2024-01-15T10:30:00+03:00", "CRM_CREATE": "Y", "CRM_SOURCE": "CALL_TRACKER", "TYPE": 2 } 

    Save CALL_ID — it is needed for finishing and attaching the recording. On Hangup, finish the call:

    POST /rest/telephony.externalcall.finish { "CALL_ID": "saved_CALL_ID", "USER_ID": 5, "DURATION": 185, "STATUS_CODE": "200", "ADD_TO_CHAT": "Y" } 

How to Transfer Call Recordings to Bitrix24?

Asterisk saves the recording file. After the call, we transfer it via REST API:

POST /rest/telephony.externalCall.attachRecord { "CALL_ID": "CALL_ID", "FILENAME": "record.mp3", "FILE_CONTENT": "<base64>" } 

For conversations longer than 5 minutes, base64 is inefficient. We use disk.file.uploadurl.prepare — get a link for direct upload.

Outgoing Calls from CRM

Manager clicks a number in the card — Asterisk must call. We subscribe to the OnExternalCallStart event and execute Originate via AMI:

Action: Originate Channel: SIP/101 Exten: +74951234567 Context: outbound Priority: 1 CallerID: "Ivanov Petr" <+74955551234> 

Case from Our Practice: Call Center for 12 Operators

A few years ago, a telecommunications company approached us. They had their own Asterisk 18, 12 operators, multi-level IVR, and queues. They needed to implement Bitrix24 for client communication history but did not want to change the working PBX.

We chose AMI integration. The difficulty arose with queues: a call could be transferred between operators. The standard AMI handler attached the call to the first operator, even though another answered. We solved it by tracking the AgentConnect event — this event records which agent actually took the call from the queue. Thanks to this, the CRM had correct assignment to the right manager.

The entire integration setup (with recording transfer and outgoing calls) took 6 business days. The company still works on this scheme — stable, without failures.

What Is Included in the Integration Work?

Stage Duration Result
Audit of current Asterisk configuration 1 day Routing scheme, provider list
Architecture design 1-2 days Choice of approach (AMI/SIP), API specification
Daemon development 3-4 days Working module with logging
Bitrix24 setup (widgets, REST user) 1 day CRM integration ready
Testing and debugging 1-2 days Verification of all scenarios
Documentation and training 1 day Administrator instructions

Total: 5 to 8 business days turnkey. Project cost depends on scheme complexity — we will calculate individually after audit.

Common Mistakes and How to Avoid Them

  • Duplicate calls in CRM. On call transfer, Asterisk creates a new channel. Filter by LinkedID in AMI events — it remains constant.
  • Recording not attached. The file may not be ready at the time of Hangup. Add a 5-10 second delay or track file appearance via inotify.
  • Incorrect assignment to operator. In queues, use AgentConnect, not Newchannel.

Why Entrust the Integration to Us?

We have over 5 years of experience with Bitrix24 and Asterisk. Completed more than 30 telephony integration projects. Certified 1C-Bitrix specialists. We guarantee stable operation and post-launch support. If you have a non-standard configuration, we will assess the project for free and offer the optimal solution. Contact us to discuss details. Get a free engineer consultation.