API 文件

Base URL:http://157.245.205.19:3000
驗證方式:Bearer Token(JWT)或 X-API-Key Header

🔐 認證

POST /api/auth/register

註冊新用戶

Request Body:

{
  "email": "user@example.com",
  "password": "password123"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiJ9...",
  "user": {
    "id": "uuid",
    "email": "user@example.com",
    "apiKey": "occ_xxxxx..."
  }
}
POST /api/auth/login

登入

Request Body:

{
  "email": "user@example.com",
  "password": "password123"
}

Response:

{
  "token": "eyJhbGciOiJIUzI1NiJ9...",
  "user": { "id": "uuid", "email": "...", "apiKey": "occ_..." }
}

👤 用戶

GET /api/user/me

取得目前用戶資料(需 Bearer Token)

Headers:Authorization: Bearer {token}

Response:

{
  "id": "uuid",
  "email": "user@example.com",
  "plan": "free",
  "matrixId": "@user:matrix.org",
  "createdAt": 1712000000000
}
PUT /api/user/matrix

設定 Matrix ID(需 Bearer Token)

Headers:Authorization: Bearer {token}

Request Body:

{
  "matrixId": "@yourname:matrix.example.com"
}

Response:

{
  "success": true,
  "matrixId": "@yourname:matrix.example.com"
}
POST /api/user/regenerate-api-key

重新產生 API Key(需 Bearer Token,舊 Key 立即失效)

Response:

{
  "apiKey": "occ_newkey..."
}

📊 Dashboard

GET /api/dashboard

取得完整 Dashboard 資料(需 Bearer Token)

Headers:Authorization: Bearer {token}

Response:

{
  "email": "user@example.com",
  "plan": "free",
  "matrixId": "@user:matrix.org",
  "apiKey": "occ_xxxx...",
  "wsUrl": "ws://157.245.205.19:3000/ws?token=...",
  "sessions": [
    {
      "id": "session-uuid",
      "created_at": 1712000000000,
      "last_seen": 1712000000000,
      "active": 1
    }
  ]
}

🔌 WebSocket

WS ws://157.245.205.19:3000/ws?token={jwt}

連線方式:使用 /api/dashboard 回傳的 wsUrl 直接 WebSocket 連線

發送訊息:

{
  "type": "ping"
}
→ 回應:
{
  "type": "pong",
  "ts": 1712000000000
}

發送通話:

{
  "type": "call",
  "callId": "call-123",
  "to": "+886912345678",
  "message": "您好,幫我預約明天門診"
}
→ 回應:
{
  "type": "call_ack",
  "callId": "call-123",
  "status": "queued"
}

⚡ 快速開始

Step 1:註冊
curl -X POST http://157.245.205.19:3000/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"password123"}'
Step 2:用 Token 取得 Dashboard(含 WS URL)
curl http://157.245.205.19:3000/api/dashboard \
  -H "Authorization: Bearer {your_token}"
Step 3:綁定 Matrix
curl -X PUT http://157.245.205.19:3000/api/user/matrix \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{"matrixId":"@user:matrix.example.com"}'