Turnkey Integration of Bitrix24 with Megafon Virtual PBX

You have corporate telephony with Megafon, but calls get lost in chaos and managers waste time on manual data entry? We set up the integration of Bitrix24 with Megafon Virtual PBX on a turnkey basis so that every conversation is automatically logged in the CRM and linked to a deal. Our team handles the entire cycle — from audit and setup to ongoing support — ensuring reliable and transparent operation of your communications.

Our competencies:

Frequently Asked Questions

Integrating Bitrix24 with Megafon Virtual PBX

Megafon Virtual PBX is cloud telephony from one of the largest Russian operators. For companies whose corporate numbers are already with Megafon, it is a natural choice of virtual PBX.

Integration with Bitrix24 is built through the Megafon API, which provides webhooks for call events.

For example, for a retail chain with 50 locations or for a call center with 20 operators, the integration provides full transparency of communications: every call is recorded in the CRM with a link to the deal and contact.

At True Tech.by, we have specialized in such integrations for over 10 years. During this time, we have delivered more than 50 projects connecting Bitrix24 with various PBXs. Megafon VATS is one of the most frequent requests, as it is inexpensive and reliable.

Below we will break down a typical architecture, common problems, and provide a ready-made handler code.

How does Megafon transmit events?

Megafon VATS works with push notifications (webhooks). In the personal account, a URL is configured for notifications about one or several types of events:

Event When it occurs
start A call has arrived at the VATS
answer The subscriber has answered
end The call has ended
record The recording is ready for download

A specific feature of Megafon: all events for a single call are combined through a single call_id. This is convenient — there is no need to generate your own identifier to link events.

Example of a notification from Megafon when a call ends:

{ "type": "end", "call_id": "meg_0123456789abcdef", "start_time": "2024-10-01 10:30:00", "end_time": "2024-10-01 10:33:05", "duration": 185, "from_number": "+74951234567", "to_number": "+74992345678", "internal_number": "102", "state": "answered", "direction": "in" }

How to set up the event handler?

The handler receives POST requests from Megafon and translates events into Bitrix24.

On the answer event:

  • Determine the USER_ID in Bitrix24 by internal_number.
  • Call telephony.externalcall.register.
  • Save the pair {meg_call_id → bitrix_call_id} in storage.

On the end event:

  • Retrieve bitrix_call_id by meg_call_id.
  • Determine STATUS_CODE from the state field according to the table:
state in the notification STATUS_CODE in Bitrix24
answered 200
not_answered 304
busy 486
  • Call telephony.externalcall.finish.

On the record event (arrives a few minutes after end):

  • By call_id, retrieve bitrix_call_id.
  • Download the recording via the link from the event.
  • Upload it via telephony.externalCall.attachRecord.

Megafon provides a link to the recording in the format:

{ "type": "record",
  "call_id": "meg_0123456789abcdef",
  "url": "https://ватс.мегафон.рф/records/...",
  "duration": 185
}

Outgoing calls via Megafon VATS

Megafon supports an API for initiating outgoing calls (click-to-call). A manager clicks on a number in Bitrix24, Bitrix24 passes the event to the handler, and the handler calls the Megafon API:

POST https://ватс.мегафон.рф/v1/click2call
{
  "from": "102",
  "to": "+74951234567",
  "line_id": "000001"
}

Megafon first calls the employee's phone, then connects to the client. At this moment, the handler must register the outgoing call in Bitrix24 via telephony.externalcall.register with TYPE=2 (outgoing).

Setting up in the personal account

In the Integrations → Notifications section:

  1. Event URL — the address of your handler.
  2. Format — JSON.
  3. Secret key (HMAC signature of requests) — for verification.

Signature verification is mandatory, otherwise the handler will accept any POST requests from anyone:

$signature = hash_hmac('sha256', $rawBody, $secretKey);
if ($signature !== $_SERVER['HTTP_X_MEGAFON_SIGNATURE']) {
    http_response_code(403);
    exit;
}

Why is the HMAC signature important?

Without signature verification, an attacker can forge a request and create fake calls in Bitrix24, which will lead to confusion and data loss. HMAC guarantees that the request was indeed sent by Megafon.

In practice, we see: up to 15% of incoming requests to the handler are fakes from bots. Verification cuts them off instantly.

Example of HMAC verification in PHP
$signature = hash_hmac('sha256', $rawBody, $secretKey);
if ($signature !== $_SERVER['HTTP_X_MEGAFON_SIGNATURE']) {
    http_response_code(403);
    exit;
}

Case from our practice: a medical clinic, 8 administrators

The clinic used Megafon VATS with 8 internal numbers and an IVR for two specializations. The problem: a call could pass through the IVR and the queue before reaching an administrator.

It was necessary to record in Bitrix24 exactly the internal number from which the employee answered, and not the initial distribution number.

Megafon passes in the internal_number field the number of the last subscriber who answered — this is exactly what is needed. Additionally: if the client hangs up in the IVR (before reaching the queue), the end event arrives with state=not_answered and an empty internal_number.

In this case, a missed call is created without a responsible person — it is visible in the general list on the reception administrator.

Thanks to our setup, the clinic saved 30% of the time on processing incoming calls and improved control over missed calls. The system processes up to 10,000 calls per month stably for two years without failures. The savings on a minute of conversation amounted to up to 20%.

Work process

  • Analysis — we study the IVR scheme, the number of employees, and reporting requirements.
  • Design — we develop the handler architecture and choose storage for linking call_id.
  • Implementation — we write the handler code and configure webhooks in the Megafon personal account.
  • Testing — we check all scenarios: incoming, outgoing, missed, call recording.
  • Deployment — we deploy on the production server and configure monitoring.

What is included in the work

  • A ready-made handler with HMAC verification and a full call processing cycle.
  • Click-to-call integration for outgoing calls.
  • Testing together with your IVR and scenarios.
  • Documentation: workflow diagram, instructions for adding new numbers.
  • Training administrators to work with the call card in Bitrix24.
  • 6-month warranty on the handler code.

Timelines and cost

The setup timeline is from 4 to 7 business days depending on the complexity of the IVR. The cost is calculated individually after analyzing your configuration. We will evaluate your project after analyzing the task. Contact us to discuss the details and get a consultation. Order a cost estimate at a convenient time.