use PAMI\Message\Action\CommandAction; public function getPjsipContacts(): array { try { $this->client->open(); $response = $this->client->send(new CommandAction('pjsip show contacts')); $this->client->close(); $raw = $response->getRawContent(); // Parse Asterisk CLI-style text into array $lines = explode("\n", $raw); $contacts = []; foreach ($lines as $line) { // Match table-style lines only if (preg_match('/^\s*(\S+)\s+(\d{1,3}(?:\.\d{1,3}){3})\s+(\d+)\s+(\w+)\s+(\d+\.\d+)\s*$/', $line, $matches)) { $contacts[] = [ 'extension' => $matches[1], 'ip' => $matches[2], 'port' => $matches[3], 'status' => $matches[4], 'rtt' => $matches[5], ]; } } return $contacts; } catch (\Throwable $e) { logger()->error('[PAMI] getPjsipContacts failed: ' . $e->getMessage()); return [ ['error' => 'Invalid data format'] ]; } }