Admin (server-only)
DANGER
Route /th/admin/* ใช้ x-admin-key ไม่ใช่ Bearer token ของผู้ใช้GOMMO_ACCESS_TOKEN (merchant) อยู่ใน .env บน server เท่านั้น
| งาน | Gommo upstream | Gommo Developer |
|---|---|---|
| ยอด merchant | POST .../ai/me + merchant token | GET /admin/merchant/balance |
| ส่ง credits | POST .../users/sendBalances | POST /admin/credits/send |
| ลงทะเบียนผู้ใช้ | POST .../auth/register | POST /admin/users/register |
Server env
| Variable | วัตถุประสงค์ |
|---|---|
GOMMO_ACCESS_TOKEN | Merchant token |
GOMMO_API_DOMAIN | Domain merchant (see .env.example) |
GOMMO_MANAGER_ID | manager_id สำหรับ register |
TOPUP_MERCHANT_BUFFER_CREDITS | Buffer เสริม (default 300k); กฎจริงคือ Gommo > 500k หลังส่ง — ตั้ง > 500k เมื่อต้องการเข้มกว่า |
ADMIN_API_KEY | ป้องกัน /th/admin/* |
กฎ Gommo: หลัง sendBalances merchant ต้องเหลือ > 500,000 credits
ยอด merchant
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ส่ง 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สิทธิ์ sendBalances มอบโดย Gommo ให้บัญชี merchant ของ domain
ลงทะเบียนผู้ใช้
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 $bodyScript: scripts/test-admin.ps1
