getAgi(); $client->answer(); } public function log($msg) { $this->logger->debug($msg); $this->getAgi()->consoleLog($msg); } public function shutdown() { return true; } public function run() { $client = $this->getAgi(); // Resolve which DialerCalls record this call belongs to $dialer_call_id = $client->getVariable('dialer_call_id'); $phone_number = trim((string) $client->getVariable('CALLERID(num)')); if (str_starts_with($phone_number, '+2')) { $phone_number = substr($phone_number, 2); } if ($dialer_call_id) { $dialer_call = DialerCalls::find($dialer_call_id); $this->dialer_call_id = $dialer_call_id; } else { $dialer_call = DialerCalls::where('number', $phone_number)->latest()->first(); if ($dialer_call) { $this->dialer_call_id = $dialer_call->id; } } if (!$dialer_call) { return true; } try { // Play the merged audio file — no DTMF collection, voice-only $client->streamFile("customIVR/{$dialer_call->id}"); } catch (\PAGI\Exception\ChannelDownException $e) { // Remote party hung up or call was rejected before/during playback } return true; } public function errorHandler($type, $message, $file, $line) { $this->log('ErrorHandler: ' . implode(' ', [$type, $message, $file, $line])); } public function signalHandler($signal) { $this->log('SignalHandler got signal: ' . $signal); $this->shutdown(); exit(0); } }