API 文件

Base URL:https://opencloud.100thy.com
驗證方式: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 https://opencloud.100thy.com/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{"email":"test@example.com","password":"password123"}'
Step 2:用 Token 取得 Dashboard(含 WS URL)
curl https://opencloud.100thy.com/api/dashboard \
  -H "Authorization: Bearer {your_token}"
Step 3:綁定 Matrix
curl -X PUT https://opencloud.100thy.com/api/user/matrix \
  -H "Authorization: Bearer {token}" \
  -H "Content-Type: application/json" \
  -d '{"matrixId":"@user:matrix.example.com"}'

📞 號碼管理

GET /api/numbers

取得目前使用者的所有號碼

Header:Authorization: Bearer {token}

{
  "numbers": [
    {
      "id": "uuid",
      "number": "+999123456789",
      "alias": "業務專線",
      "created_at": 1712000000000
    }
  ]
}
POST /api/numbers

建立新號碼

Header:Authorization: Bearer {token}

{
  "alias": "業務專線",
  "pin": "1234",
  "captchaToken": "uuid"
}
{
  "id": "uuid",
  "number": "+999123456789",
  "alias": "業務專線",
  "created_at": 1712000000000
}

限制:每個用戶最多 5 個號碼

PUT /api/numbers/:id/alias

更新號碼別名

{"alias": "新別名"}
PUT /api/numbers/:id/pin

更改 PIN

{
  "currentPin": "1234",
  "newPin": "5678"
}

注意:需驗證目前 PIN

DELETE /api/numbers/:id

刪除號碼。刪除後相關通話記錄也會一併移除。

📋 通話記錄

GET /api/history

取得通話記錄列表

Query 參數:

  • statusanswered | missed | blocked | all(預設 all)
  • limit — 每頁數量(預設 50)
  • offset — 分頁偏移(預設 0)
{
  "history": [
    {
      "id": "uuid",
      "number_id": "uuid",
      "caller_num": "+886912345678",
      "status": "answered",
      "duration": 45,
      "created_at": 1712000000000,
      "number": "+999123456789",
      "alias": "業務專線"
    }
  ],
  "total": 128,
  "limit": 50,
  "offset": 0
}

🔐 CAPTCHA 驗證

GET /api/captcha

取得驗證題目(簡單數學加法)

{
  "a": 3,
  "b": 7,
  "question": "3 + 7 = ?"
}
POST /api/captcha/verify

驗證答案,正確後取得 token(10 分鐘內有效)

{
  "a": 3,
  "b": 7,
  "answer": 10
}
→ 成功:
{ "token": "uuid" }
→ 失敗:
{ "error": "答案錯誤" }
class="site-footer">