Mango Office IP Telephony Integration on Website
Mango Office is a Russian virtual PBX for business. It provides cloud telephony, call recording, analytics, and API for integration with your website and CRM.
What Integration Provides
- Pop-up with customer data on incoming call (manager sees who is calling)
- Click-to-call: calling button directly in customer card or order
- Call history linked to order/customer
- Routing: different department depending on page or product
Webhook on Call
Mango Office sends POST requests on call events (incoming, answered, completed):
Route::post('/webhooks/mango', function (Request $request) {
$json = json_decode($request->json, true);
$event = $json['event'];
$call = $json['call_id'];
$caller = $json['from']['number'];
if ($event === 'call_arrived') {
$customer = Customer::where('phone', normalizePhone($caller))->first();
// Notify manager via WebSocket
broadcast(new MangoCallArrived($call, $caller, $customer));
}
if ($event === 'call_finished') {
CallRecord::create([
'mango_call_id' => $call,
'duration' => $json['duration'],
'recording' => $json['recording_url'] ?? null,
'caller' => $caller
]);
}
});
Click-to-Call via API
$response = Http::withHeaders(['X-Mango-VPbxApiKey' => env('MANGO_API_KEY')])
->post('https://app.mango-office.ru/vpbx/commands/callback', [
'json' => json_encode([
'command_id' => uniqid(),
'extension' => $agentExtension, // agent's extension number in PBX
'number' => $customerPhone,
'line_number'=> env('MANGO_LINE_NUMBER')
]),
'sign' => hash('sha256', env('MANGO_API_KEY') . json_encode([...]) . env('MANGO_SALT'))
]);
Getting Call Recordings
$recordings = Http::withHeaders(['X-Mango-VPbxApiKey' => env('MANGO_API_KEY')])
->post('https://app.mango-office.ru/vpbx/stats/calls/recording/post_read', [
'json' => json_encode([
'start' => strtotime('today midnight'),
'end' => time(),
'fields' => ['start_time', 'duration', 'direction', 'from_number', 'to_number', 'recording']
])
])->json();
Phone Number Normalization
The key issue is phone normalization for customer lookup. Mango sends numbers in different formats, and they may be stored differently in the database. A unified normalization function:
function normalizePhone(string $phone): string {
$phone = preg_replace('/[^0-9]/', '', $phone);
if (strlen($phone) === 10) $phone = '7' . $phone;
if (str_starts_with($phone, '8')) $phone = '7' . substr($phone, 1);
return '+' . $phone;
}
Integration timeline: 2–4 days for full integration with pop-up, click-to-call and call history.







