Add admin views for quick replies, settings, and ticket details
- Created `quick-replies.blade.php` for managing quick replies. - Added `settings.blade.php` for admin settings management. - Implemented `ticket-show.blade.php` to display ticket details. - Introduced `timeline-card.blade.php` component for displaying timeline information. Enhance quick reply management functionality - Developed `quick-reply-manager.blade.php` for creating and editing quick replies. - Integrated Livewire for dynamic interaction and validation. Implement settings page for AI configuration - Created `settings-page.blade.php` for managing AI settings, including prompts and provider instances. - Added functionality for managing models and embeddings. Add ticket show functionality with real-time updates - Implemented ticket details view with processing status and tool call logs. - Added support for displaying article suggestions and error messages. Create unit tests for AI classifier and domain info tool - Added `AIClassifierServiceTest.php` to validate AI classifier functionality. - Implemented `DomainInfoToolTest.php` for domain parameter validation. - Created `OxxaClientTest.php` to test API interactions and password hashing.
This commit is contained in:
70
app/Services/Tools/OxxaClient.php
Normal file
70
app/Services/Tools/OxxaClient.php
Normal file
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Tools;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use InvalidArgumentException;
|
||||
use RuntimeException;
|
||||
use SimpleXMLElement;
|
||||
|
||||
class OxxaClient
|
||||
{
|
||||
public function request(string $command, array $data = []): array|SimpleXMLElement
|
||||
{
|
||||
$endpoint = rtrim((string) config('services.oxxa.endpoint'), '?&');
|
||||
if ($endpoint === '') {
|
||||
throw new InvalidArgumentException('OXXA_API_ENDPOINT is not configured.');
|
||||
}
|
||||
|
||||
if (! isset($data['apiuser'], $data['apipassword'])) {
|
||||
throw new InvalidArgumentException('Oxxa credentials are required.');
|
||||
}
|
||||
|
||||
$payload = $data;
|
||||
$payload['apipassword'] = 'MD5'.md5((string) $payload['apipassword']);
|
||||
|
||||
$response = Http::timeout((int) config('services.oxxa.timeout', 60))
|
||||
->get($endpoint, ['command' => $command] + $payload)
|
||||
->throw();
|
||||
|
||||
$xml = simplexml_load_string((string) $response->body(), SimpleXMLElement::class, LIBXML_NOCDATA);
|
||||
if (! $xml instanceof SimpleXMLElement) {
|
||||
throw new RuntimeException('Oxxa returned invalid XML.');
|
||||
}
|
||||
|
||||
$responseData = $this->xmlToArray($xml);
|
||||
$statusCode = trim((string) data_get($responseData, 'order.status_code', ''));
|
||||
$statusDescription = trim((string) data_get($responseData, 'order.status_description', ''));
|
||||
|
||||
if ($statusCode === 'XMLERR 1') {
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => 'Credentials are incorrect. Please change the credentials in the registrar module.',
|
||||
'status_code' => $statusCode,
|
||||
'status_description' => $statusDescription,
|
||||
];
|
||||
}
|
||||
|
||||
if (str_contains($statusCode, 'XMLOK')) {
|
||||
return [
|
||||
'ok' => true,
|
||||
'status_code' => $statusCode,
|
||||
'status_description' => $statusDescription,
|
||||
'data' => $responseData,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'ok' => false,
|
||||
'error' => trim($statusCode.' '.$statusDescription),
|
||||
'status_code' => $statusCode,
|
||||
'status_description' => $statusDescription,
|
||||
'data' => $responseData,
|
||||
];
|
||||
}
|
||||
|
||||
private function xmlToArray(SimpleXMLElement $xml): array
|
||||
{
|
||||
return json_decode(json_encode($xml, JSON_THROW_ON_ERROR), true, 512, JSON_THROW_ON_ERROR);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user