Mini API: support ticket endpoints (replaces Afia support chat).
Deploy Ladill Mini / deploy (push) Successful in 28s

Support is now a ticket system proxied to the central identity support API:
GET/POST /mini/support/tickets and GET /mini/support/tickets/{id}. Removed the
Afia-backed /support/chat route.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
isaacclad
2026-06-11 12:29:35 +00:00
co-authored by Claude Opus 4.8
parent af1f197059
commit 3406bd730a
2 changed files with 43 additions and 32 deletions
@@ -2,46 +2,55 @@
namespace App\Http\Controllers\Api\Mini;
use App\Http\Controllers\Api\Concerns\CallsIdentityApi;
use App\Http\Controllers\Controller;
use App\Services\Afia\AfiaService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
/**
* Support tickets proxies to the central support system (auth.ladill.com),
* so tickets land in the same admin support queue as every other Ladill app.
*/
class SupportController extends Controller
{
public function chat(Request $request, AfiaService $afia): JsonResponse
use CallsIdentityApi;
public function tickets(): JsonResponse
{
$validated = $request->validate([
'message' => ['required', 'string', 'max:2000'],
'history' => ['nullable', 'array', 'max:20'],
'history.*.role' => ['nullable', 'string'],
'history.*.text' => ['nullable', 'string'],
$response = $this->identitySend('GET', '/api/identity/support/tickets?user='.urlencode((string) ladill_account()->public_id), []);
return response()->json(['data' => $response->json('data', [])]);
}
public function ticket(int $ticket): JsonResponse
{
$response = $this->identitySend(
'GET',
'/api/identity/support/tickets/'.$ticket.'?user='.urlencode((string) ladill_account()->public_id),
[],
);
if ($response->status() === 404) {
return response()->json(['message' => 'Ticket not found.'], 404);
}
return response()->json(['data' => $response->json('data')]);
}
public function store(Request $request): JsonResponse
{
$data = $request->validate([
'subject' => ['required', 'string', 'max:255'],
'message' => ['required', 'string', 'max:5000'],
'priority' => ['sometimes', 'in:low,normal,high'],
]);
if (! $afia->enabled()) {
return response()->json(['message' => 'Support chat is not available right now.'], 503);
}
$response = $this->identitySend('POST', '/api/identity/support/tickets', array_merge(
['user' => ladill_account()->public_id],
$data,
));
$this->rethrowValidation($response, 'subject');
try {
$reply = $afia->chat(trim($validated['message']), $validated['history'] ?? [], $this->context());
} catch (\Throwable $e) {
report($e);
return response()->json(['message' => 'We could not respond right now. Please try again.'], 502);
}
return response()->json(['data' => ['reply' => $reply]]);
}
/** @return array<string, mixed> */
private function context(): array
{
$account = ladill_account();
return [
'app' => 'Ladill Mini',
'description' => 'Ladill Mini is a payments app: merchants create payment QR codes and links, collect payments, and track takings and payouts.',
'account_name' => $account?->name,
];
return response()->json(['data' => $response->json('data')], 201);
}
}