Mini API: support ticket endpoints (replaces Afia support chat).
Deploy Ladill Mini / deploy (push) Successful in 28s
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:
co-authored by
Claude Opus 4.8
parent
af1f197059
commit
3406bd730a
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -55,6 +55,8 @@ Route::prefix('v1')->group(function () {
|
||||
Route::get('/mini/wallet/withdrawals', [MiniWalletController::class, 'withdrawals'])->name('api.mini.wallet.withdrawals');
|
||||
Route::post('/mini/wallet/withdraw', [MiniWalletController::class, 'withdraw'])->name('api.mini.wallet.withdraw');
|
||||
|
||||
Route::post('/mini/support/chat', [MiniSupportController::class, 'chat'])->name('api.mini.support.chat');
|
||||
Route::get('/mini/support/tickets', [MiniSupportController::class, 'tickets'])->name('api.mini.support.tickets');
|
||||
Route::post('/mini/support/tickets', [MiniSupportController::class, 'store'])->name('api.mini.support.tickets.store');
|
||||
Route::get('/mini/support/tickets/{ticket}', [MiniSupportController::class, 'ticket'])->whereNumber('ticket')->name('api.mini.support.ticket');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user