CRM/backend/app/Services/VoIP/VoIPManager.php

50 خطوط
1.4 KiB
PHP

<?php
namespace App\Services\VoIP;
use App\Models\Setting;
class VoIPManager
{
private ?VoIPProviderInterface $provider = null;
public function provider(): VoIPProviderInterface
{
if ($this->provider === null) {
$providerName = Setting::where('key', 'voip_provider')->value('value') ?? (app()->environment('testing') ? 'mock' : 'none');
if (app()->environment('testing') && $providerName === 'none') {
$providerName = 'mock';
}
$this->provider = match ($providerName) {
'ami' => new AmiProvider,
'api' => new ApiProvider,
'socket' => new SocketProvider,
'mock' => app()->environment('testing') ? new MockProvider : new DisabledProvider,
default => new DisabledProvider,
};
}
return $this->provider;
}
public function initiateCall(string $phone, ?string $callerId = null): array
{
return $this->provider()->initiateCall($phone, $callerId);
}
public function getCallStatus(string $providerCallId): array
{
return $this->provider()->getCallStatus($providerCallId);
}
public function getRecordingUrl(string $providerCallId): ?string
{
return $this->provider()->getRecordingUrl($providerCallId);
}
public function testConnection(): array
{
return $this->provider()->testConnection();
}
}