Files
ladill-frontdesk/app/Services/Queue/QueueClient.php
T
isaaccladandCursor 014976b757
Deploy Ladill Frontdesk / deploy (push) Successful in 50s
Sync Frontdesk queue integration flag with Ladill Queue on enable.
Mirror Care fix so provision and settings keep frontdesk_enabled in sync.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-05 22:06:04 +00:00

117 lines
3.0 KiB
PHP

<?php
namespace App\Services\Queue;
use Illuminate\Http\Client\RequestException;
use Illuminate\Support\Facades\Http;
class QueueClient
{
private function base(): string
{
return rtrim((string) config('frontdesk.queue.api_url'), '/');
}
private function token(): string
{
return (string) (config('frontdesk.queue.api_key') ?? '');
}
private function http(string $owner)
{
return Http::withToken($this->token())
->acceptJson()
->timeout(12)
->withQueryParameters(['owner' => $owner]);
}
public function configured(): bool
{
return $this->token() !== '' && $this->base() !== '';
}
/**
* @return array<string, mixed>
*/
public function status(string $owner): array
{
$response = $this->http($owner)->get($this->base().'/integrations/status');
$response->throw();
return (array) ($response->json('data') ?? []);
}
/**
* @return array<string, mixed>
*/
public function enable(string $owner, string $organizationName, ?string $branchName = null): array
{
$this->http($owner)->post($this->base().'/integrations/provision', array_filter([
'organization_name' => $organizationName,
'branch_name' => $branchName,
'industry' => 'visitor',
]))->throw();
return $this->syncIntegration($owner, true);
}
/**
* @return array<string, mixed>
*/
public function syncIntegration(string $owner, bool $enabled = true): array
{
$response = $this->http($owner)->patch($this->base().'/integrations', [
'frontdesk_enabled' => $enabled,
]);
$response->throw();
return (array) ($response->json('data') ?? []);
}
public function isLinked(string $owner): bool
{
if (! $this->configured()) {
return false;
}
try {
$status = $this->status($owner);
return (bool) ($status['provisioned'] ?? false)
&& (bool) data_get($status, 'integrations.frontdesk', false);
} catch (RequestException) {
return false;
}
}
/**
* @return list<array<string, mixed>>
*/
public function counters(string $owner): array
{
$response = $this->http($owner)->get($this->base().'/counters');
$response->throw();
return (array) ($response->json('data') ?? []);
}
/**
* @return array<string, mixed>
*/
public function console(string $owner, string $counterUuid): array
{
$response = $this->http($owner)->get($this->base().'/counters/'.$counterUuid.'/console');
$response->throw();
return (array) ($response->json('data') ?? []);
}
/**
* @param array<string, mixed> $payload
*/
public function consoleAction(string $owner, string $counterUuid, array $payload): void
{
$this->http($owner)->post($this->base().'/counters/'.$counterUuid.'/console', $payload)->throw();
}
}