Deploy Ladill Frontdesk / deploy (push) Successful in 47s
Match Care/Queue hand-off UX so visitors keep their ticket number across services. Co-authored-by: Cursor <cursoragent@cursor.com>
121 lines
3.1 KiB
PHP
121 lines
3.1 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
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function consoleAction(string $owner, string $counterUuid, array $payload): array
|
|
{
|
|
$response = $this->http($owner)->post($this->base().'/counters/'.$counterUuid.'/console', $payload);
|
|
$response->throw();
|
|
|
|
return (array) ($response->json('data') ?? []);
|
|
}
|
|
}
|