Skip to content

Admin (chỉ server) ​

DANGER

Route /vi/admin/* dùng x-admin-key, không phải Bearer token user. GOMMO_ACCESS_TOKEN (merchant) chỉ nằm trong .env server.

Thao tácGommo upstreamGommo Developer
Merchant balancePOST .../ai/me + merchant tokenGET /admin/merchant/balance
Send creditsPOST .../users/sendBalancesPOST /admin/credits/send
Register userPOST .../auth/registerPOST /admin/users/register

Server env ​

BiếnMục đích
GOMMO_ACCESS_TOKENMerchant token
GOMMO_API_DOMAINDomain merchant (xem .env.example)
GOMMO_MANAGER_IDmanager_id cho register
TOPUP_MERCHANT_BUFFER_CREDITSBuffer tùy chọn (mặc định 300k); rule thực tế là Gommo > 500k sau gửi — chỉ set > 500k nếu muốn chặt hơn
ADMIN_API_KEYBảo vệ /vi/admin/*

Quy tắc Gommo: sau sendBalances, merchant phải còn > 500.000 credits.


Merchant balance ​

bash
curl.exe "http://localhost:3001/admin/merchant/balance" ^
  -H "x-admin-key: YOUR_ADMIN_KEY"
powershell
$h = @{ 'x-admin-key' = $env:ADMIN_API_KEY }
Invoke-RestMethod "http://localhost:3001/admin/merchant/balance" -Headers $h

Send credits ​

json
{
  "username": "gommo_username",
  "value": 100,
  "message": "Topup test",
  "type": "credits_ai"
}
bash
curl.exe -X POST "http://localhost:3001/admin/credits/send" ^
  -H "x-admin-key: YOUR_ADMIN_KEY" -H "Content-Type: application/json" ^
  -d "{\"username\":\"user1\",\"value\":100,\"message\":\"Test topup\"}"
powershell
$body = @{ username = 'user1'; value = 100; message = 'Test topup' } | ConvertTo-Json
Invoke-RestMethod -Method POST -Uri "http://localhost:3001/admin/credits/send" `
  -Headers @{ 'x-admin-key' = $env:ADMIN_API_KEY; 'Content-Type' = 'application/json' } `
  -Body $body

Quyền sendBalances do Gommo cấp cho tài khoản merchant domain.


Register user ​

bash
curl.exe -X POST "http://localhost:3001/admin/users/register" ^
  -H "x-admin-key: YOUR_ADMIN_KEY" -H "Content-Type: application/json" ^
  -d "{\"email\":\"[email protected]\",\"password\":\"secret12\",\"phone\":\"0900000000\"}"
powershell
$body = @{
  email = '[email protected]'
  password = 'secret12'
  phone = '0900000000'
} | ConvertTo-Json
Invoke-RestMethod -Method POST -Uri "http://localhost:3001/admin/users/register" `
  -Headers @{ 'x-admin-key' = $env:ADMIN_API_KEY; 'Content-Type' = 'application/json' } `
  -Body $body

Script: scripts/test-admin.ps1