Files
ladill-mini/app/Http/Controllers/Api/Mini/SupportController.php
T
isaaccladandClaude Opus 4.8 c39e38cbe0
Deploy Ladill Mini / deploy (push) Successful in 40s
Mini API: account settings, wallet & support endpoints for the app.
Adds /api/v1/mini account (settings, profile, change-password), wallet (balance
+ ledger, Paystack top-up) and support (Afia chat) endpoints. Account/profile/
password/top-up proxy to the central identity API via a CallsIdentityApi trait;
notifications, wallet balance and support chat are served locally.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-11 11:03:33 +00:00

48 lines
1.5 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Mini;
use App\Http\Controllers\Controller;
use App\Services\Afia\AfiaService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class SupportController extends Controller
{
public function chat(Request $request, AfiaService $afia): JsonResponse
{
$validated = $request->validate([
'message' => ['required', 'string', 'max:2000'],
'history' => ['nullable', 'array', 'max:20'],
'history.*.role' => ['nullable', 'string'],
'history.*.text' => ['nullable', 'string'],
]);
if (! $afia->enabled()) {
return response()->json(['message' => 'Support chat is not available right now.'], 503);
}
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,
];
}
}