Wusper Chat API 說明文件 Wusper Chat API 说明文档 Wusper Chat API docs

Base URL · https://chat.wusper.com

打哪:Base URL 與路徑一覽

所有 HTTP 請求都打到這個主機:
https://chat.wusper.com

Bearer API 前綴一律是 /api/v1/…。設定頁的靜態文件/套件另見下方連結。

三種金鑰共用的路徑:

方法完整 URL說明
GEThttps://chat.wusper.com/api/v1/me查金鑰類型、擁有者、綁定房間/Bot
GET↑WSwss://chat.wusper.com/api/v1/ws三種金鑰即時進線(Bearer 或 ?access_token=)
GEThttps://chat.wusper.com/api/version版本與文件/套件路徑(無需 Bearer)

① 私人對話(type: private,金鑰 wc_…)

方法完整 URL說明
GEThttps://chat.wusper.com/api/v1/private/messages?limit=50&order=newest讀取綁定私人房間訊息(order=oldest|newest,預設 oldest)
POSThttps://chat.wusper.com/api/v1/private/messages送訊/HTML/流式 · {"body"|"html"};加 stream:true 開流式

② 代管(type: delegate,金鑰 wc_…)

方法完整 URL說明
GEThttps://chat.wusper.com/api/v1/friends列出好友
GEThttps://chat.wusper.com/api/v1/messages?with=<userId>&order=newest讀取與好友的 DM(需 ACL;可 order)
POSThttps://chat.wusper.com/api/v1/messages代帳號送 DM/HTML/流式 · {"to","body"|"html"};stream:true 開流式

③ Bot(type: bot,金鑰 wc_…;分享碼 wbot_… 不是 Bearer)

方法完整 URL說明
GEThttps://chat.wusper.com/api/v1/bot/meBot 資料
GEThttps://chat.wusper.com/api/v1/dm/peers可私訊的對象
GEThttps://chat.wusper.com/api/v1/dm/messages?with=<userId>&order=newest讀取與 peer 的 DM(可 order)
POSThttps://chat.wusper.com/api/v1/dm/messagesBot 送 DM/HTML/流式 · {"to","body"|"html"};stream:true 開流式
GEThttps://chat.wusper.com/api/v1/threads三人串列表
GEThttps://chat.wusper.com/api/v1/threads/<threadId>/messages?order=newest讀取串訊息(可 order)
POSThttps://chat.wusper.com/api/v1/threads/<threadId>/messages送串/HTML/流式 · {"body"|"html"};stream:true 開流式

相關靜態資源:

  • 本頁:https://chat.wusper.com/api-docs
  • OpenAPI:https://chat.wusper.com/docs/openapi-v1.yaml
  • Markdown:https://chat.wusper.com/docs/api-v1.md
  • 套件 zip:https://chat.wusper.com/api-packages/wusper-chat-api-packages.zip

打哪:Base URL 与路径一览

所有 HTTP 请求都打到这个主机:
https://chat.wusper.com

Bearer API 前缀一律是 /api/v1/…。

三种密钥共用:

方法完整 URL说明
GEThttps://chat.wusper.com/api/v1/me查密钥类型、拥有者、绑定房间/Bot
GEThttps://chat.wusper.com/api/version版本与文档/套件路径(无需 Bearer)

① 私人对话(type: private,密钥 wc_…)

方法完整 URL说明
GEThttps://chat.wusper.com/api/v1/private/messages?limit=50&order=newest读取绑定私人房间消息(order=oldest|newest,默认 oldest)
POSThttps://chat.wusper.com/api/v1/private/messages发送/HTML/流式 · {"body"|"html"};stream:true 开流式

② 代管(type: delegate,密钥 wc_…)

方法完整 URL说明
GEThttps://chat.wusper.com/api/v1/friends列出好友
GEThttps://chat.wusper.com/api/v1/messages?with=<userId>读取与好友的 DM(需 ACL)
POSThttps://chat.wusper.com/api/v1/messages代账号发 DM/HTML/流式 · {"to","body"|"html", stream?:true}

③ Bot(type: bot,密钥 wc_…;分享码 wbot_… 不是 Bearer)

方法完整 URL说明
GEThttps://chat.wusper.com/api/v1/bot/meBot 资料
GEThttps://chat.wusper.com/api/v1/dm/peers可私信对象
GEThttps://chat.wusper.com/api/v1/dm/messages?with=<userId>读取与 peer 的 DM
POSThttps://chat.wusper.com/api/v1/dm/messagesBot 发 DM/HTML/流式 · {"to","body"|"html", stream?:true}
GEThttps://chat.wusper.com/api/v1/threads三人串列表
GEThttps://chat.wusper.com/api/v1/threads/<threadId>/messages读取串消息
POSThttps://chat.wusper.com/api/v1/threads/<threadId>/messages发送串/HTML/流式 · {"body"|"html", stream?:true}
  • 本页:https://chat.wusper.com/api-docs
  • OpenAPI:https://chat.wusper.com/docs/openapi-v1.yaml
  • Markdown:https://chat.wusper.com/docs/api-v1.md
  • 套件 zip:https://chat.wusper.com/api-packages/wusper-chat-api-packages.zip

Where to hit: base URL + every path

Every HTTP call goes to:
https://chat.wusper.com

Bearer routes live under /api/v1/….

Common

MethodFull URLNotes
GEThttps://chat.wusper.com/api/v1/meKey type, owner, bound room / bot
GEThttps://chat.wusper.com/api/versionVersion + docs/package paths (no Bearer)

① Private chat (type: private, secret wc_…)

MethodFull URLNotes
GEThttps://chat.wusper.com/api/v1/private/messages?limit=50List bound private-room messages
POSThttps://chat.wusper.com/api/v1/private/messagesSend text/HTML/stream · {"body"|"html"}; stream:true starts stream

② Delegate / managed (type: delegate, secret wc_…)

MethodFull URLNotes
GEThttps://chat.wusper.com/api/v1/friendsList friends
GEThttps://chat.wusper.com/api/v1/messages?with=<userId>DM history (ACL required)
POSThttps://chat.wusper.com/api/v1/messagesSend as owner · {"to","body"|"html"}; stream:true starts stream

③ Bot (type: bot, secret wc_…; share code wbot_… is NOT Bearer)

MethodFull URLNotes
GEThttps://chat.wusper.com/api/v1/bot/meBot profile
GEThttps://chat.wusper.com/api/v1/dm/peersDM-capable peers
GEThttps://chat.wusper.com/api/v1/dm/messages?with=<userId>DM history
POSThttps://chat.wusper.com/api/v1/dm/messagesSend DM · {"to","body"|"html"}; stream:true starts stream
GEThttps://chat.wusper.com/api/v1/threadsGroup-of-3 threads
GEThttps://chat.wusper.com/api/v1/threads/<threadId>/messagesThread history
POSThttps://chat.wusper.com/api/v1/threads/<threadId>/messagesSend text/HTML/stream · {"body"|"html"}; stream:true

驗證(Auth)

三種 API 金鑰的秘密字串都以 wc_ 開頭。請求時放在 Authorization:

Authorization: Bearer wc_YOUR_SECRET
Content-Type: application/json
Accept: application/json
  • 金鑰在網站 設置 → API 建立;建立/重新產生時只顯示一次。
  • Bot 分享碼形如 wbot_…,只用於在 UI 把 Bot 加成好友/認領,不能當 Bearer。
  • 訊息本文上限約 4000 字元(欄位 body;私人房間亦接受別名 text)。
  • HTML 組件:傳送 {"html":"<button id=ok>OK</button>"}(或 format:"html")。聊天內以隔離組件顯示;使用者點按鈕會 webhook message.interaction 回你的 API(含 message_id、element.id/label)。亦可 GET /api/v1/interactions 輪詢。HTML 上限 48KB,伺服器會消毒。預設 interact:true(點按鈕回呼);設 interact:false(或 report_actions:false)關閉回報。
  • 流式傳輸:在一般送訊 POST 加 "stream": true(缺省/false=一次送完)。之後 POST …/messages/:id/chunks → …/complete。…/messages/stream 為別名。流式時 HTML 照常接受並顯示,但按鈕互動不適用(回傳 warning: "html_components_unavailable_while_streaming",interact 強制 false)。

验证(Auth)

三种 API 密钥的秘密字符串都以 wc_ 开头。请求时放在 Authorization:

Authorization: Bearer wc_YOUR_SECRET
Content-Type: application/json
Accept: application/json
  • 密钥在网站 设置 → API 创建;创建/重新生成时只显示一次。
  • Bot 分享码形如 wbot_…,只用于在 UI 把 Bot 加成好友/认领,不能当 Bearer。
  • 消息正文上限约 4000 字符(字段 body)。
  • HTML 组件:发送 {"html":"…"};用户点击按钮会 webhook message.interaction 回发送方 API(含 message_id、element id/label)。也可 GET /api/v1/interactions。
  • 流式传输:普通发讯 POST 加 "stream": true(缺省/false=一次发完)。随后 chunks → complete。流式时 HTML 照常接收显示,但按钮互动不适用(警告 html_components_unavailable_while_streaming)。

Auth

All three API secrets start with wc_. Send:

Authorization: Bearer wc_YOUR_SECRET
Content-Type: application/json
Accept: application/json
  • Create keys in Settings → API; the secret is shown once on create / regenerate.
  • Bot share codes (wbot_…) are for friend-claim in the UI — not Bearer tokens.
  • Message body max ≈ 4000 characters (body).
  • HTML components: send {"html":"<button id=ok>OK</button>"}. Clicks webhook message.interaction to your key (message_id + element id/label). Poll GET /api/v1/interactions. Sanitized, max 48KB. Default interact:true (clicks callback); set interact:false / report_actions:false to disable.
  • Streaming: add "stream": true on the normal send POST (omit/false = one-shot). Then …/messages/:id/chunks → …/complete. HTML is accepted while streaming, but interactive components are disabled (warning: "html_components_unavailable_while_streaming", interact: false).

如何建立三種金鑰

  1. 登入 https://chat.wusper.com → 個人中心/設置 → API。
  2. 按 建立 API,選類型:
    • private 私人對話 — 綁定一個私人房間,之後所有讀寫都打該房間。
    • delegate 代管 — 以你的帳號身分讀好友、代發 DM;每個好友必須在管理頁開啟 ACL。
    • bot Bot — 獨立 Bot 身分;可用邀請/wbot_ 分享碼加人;可設 Webhook、三人串。
  3. 複製顯示的 wc_… 秘密;關掉後無法再看(只能重新產生)。

如何创建三种密钥

  1. 登录 https://chat.wusper.com → 个人中心/设置 → API。
  2. 点 建立 API,选类型:私人对话 / 代管 / Bot。
  3. 复制显示的 wc_… 秘密;关掉后无法再看(只能重新生成)。

Creating keys

  1. Sign in at https://chat.wusper.com → Settings → API.
  2. Create API → pick private, delegate, or bot.
  3. Copy the wc_… secret (shown once).
private 私人對話 API — 綁定單一私人房間 私人对话 API — 绑定单一私人房间 Private chat API — one bound private room

用途:把一個房間當「頻道/inbox」,用程式讀寫。金鑰建立時選定房間;之後路徑固定,無需再帶 room id。

收訊

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  'https://chat.wusper.com/api/v1/private/messages?limit=50'

送訊

curl -sS -X POST \
  -H "Authorization: Bearer $WUSPER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"body":"hello from private API"}' \
  https://chat.wusper.com/api/v1/private/messages

送 HTML 組件(可點按鈕 → 回呼你的 Webhook)

curl -sS -X POST \
  -H "Authorization: Bearer $WUSPER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"html":""}' \
  https://chat.wusper.com/api/v1/private/messages

JS SDK

import { WusperChatClient } from '@wusper/chat-sdk';
const client = new WusperChatClient({ apiKey: process.env.WUSPER_API_KEY });
console.log(await client.me());
console.log(await client.listPrivateMessages(50));
await client.sendPrivateMessage('hello from JS');

Python SDK

from wusper_chat import WusperChatClient
import os
client = WusperChatClient(os.environ["WUSPER_API_KEY"])
print(client.me())
print(client.list_private_messages(50))
client.send_private_message("hello from Python")

可選:在金鑰管理頁設定 webhook_url,房間有新訊息時伺服器會 POST(見 Webhooks)。

用途:把一个房间当「频道/inbox」,用程序读写。密钥创建时选定房间;之后路径固定。

收信

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  'https://chat.wusper.com/api/v1/private/messages?limit=50'

送信

curl -sS -X POST \
  -H "Authorization: Bearer $WUSPER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"body":"hello from private API"}' \
  https://chat.wusper.com/api/v1/private/messages

JS / Python

// JS
await client.listPrivateMessages(50);
await client.sendPrivateMessage('hello');

# Python
client.list_private_messages(50)
client.send_private_message("hello")

Bound to one private room at key creation. Paths need no room id.

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  'https://chat.wusper.com/api/v1/private/messages?limit=50'

curl -sS -X POST -H "Authorization: Bearer $WUSPER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"body":"hello from private API"}' \
  https://chat.wusper.com/api/v1/private/messages
await client.listPrivateMessages(50);
await client.sendPrivateMessage('hello from JS');
# Python: list_private_messages / send_private_message
delegate 代管 API — 以帳號身分操作好友 DM 代管 API — 以账号身份操作好友 DM Delegate / managed API — act as the owner account

用途:自動化你自己的帳號(客服腳本、橋接等)。每個要操作的好友必須在 設置 → API → 管理該金鑰 開啟對應 ACL,否則讀寫會被拒。

列好友

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  https://chat.wusper.com/api/v1/friends

收/送 DM

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  "https://chat.wusper.com/api/v1/messages?with=$FRIEND_ID&limit=50"

curl -sS -X POST \
  -H "Authorization: Bearer $WUSPER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d "{\"to\":\"$FRIEND_ID\",\"body\":\"hello via delegate\"}" \
  https://chat.wusper.com/api/v1/messages

JS / Python

const friends = await client.listFriends();
await client.listDelegateMessages(friendId, 50);
await client.sendDelegateMessage(friendId, 'hello via delegate');

# Python
client.list_friends()
client.list_delegate_messages(friend_id, 50)
client.send_delegate_message(friend_id, "hello via delegate")

用途:自动化你自己的账号。每个要操作的好友必须在管理页开启 ACL。

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  https://chat.wusper.com/api/v1/friends
curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  "https://chat.wusper.com/api/v1/messages?with=$FRIEND_ID"
curl -sS -X POST -H "Authorization: Bearer $WUSPER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d "{\"to\":\"$FRIEND_ID\",\"body\":\"hello via delegate\"}" \
  https://chat.wusper.com/api/v1/messages

Acts as the owner. Enable each friend under Settings → API → manage (ACL) before DM read/write.

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  https://chat.wusper.com/api/v1/friends
# GET/POST https://chat.wusper.com/api/v1/messages
await client.sendDelegateMessage(friendId, 'hello');
bot Bot API — 獨立身分 · DM · 三人串 · Webhook Bot API — 独立身份 · DM · 三人串 · Webhook Bot API — own identity · DMs · group-of-3 · webhooks

用途:對外提供 Bot。Bearer 仍是 wc_…。分享碼 wbot_… 給別人在 App 內認領/加好友用。Peer 需擁有者邀請或分享碼認領後,才能用 DM 路徑互通。

身分與 peers

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  https://chat.wusper.com/api/v1/bot/me

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  https://chat.wusper.com/api/v1/dm/peers

Bot DM 收/送

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  "https://chat.wusper.com/api/v1/dm/messages?with=$PEER_ID&limit=50"

curl -sS -X POST \
  -H "Authorization: Bearer $WUSPER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d "{\"to\":\"$PEER_ID\",\"body\":\"hi from bot\"}" \
  https://chat.wusper.com/api/v1/dm/messages

三人串(owner + friend + bot)

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  https://chat.wusper.com/api/v1/threads

curl -sS -H "Authorization: Bearer $WUSPER_API_KEY" \
  "https://chat.wusper.com/api/v1/threads/$THREAD_ID/messages?limit=50"

curl -sS -X POST \
  -H "Authorization: Bearer $WUSPER_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"body":"hello thread"}' \
  "https://chat.wusper.com/api/v1/threads/$THREAD_ID/messages"

JS / Python

await client.botMe();
const { peers } = await client.listDmPeers();
await client.sendDm(peers[0].id, 'hi');
const { threads } = await client.listThreads();
await client.sendThreadMessage(threads[0].id, 'hello thread');

# Python
client.bot_me(); client.list_dm_peers(); client.send_dm(peer_id, "hi")
client.list_threads(); client.send_thread_message(thread_id, "hello thread")

Bearer 仍是 wc_…。分享码 wbot_… 只用于认领/加好友。

https://chat.wusper.com/api/v1/bot/me
https://chat.wusper.com/api/v1/dm/peers
https://chat.wusper.com/api/v1/dm/messages
https://chat.wusper.com/api/v1/threads
https://chat.wusper.com/api/v1/threads/<threadId>/messages

Bearer is still wc_…. Share code wbot_… is for UI claim only. Peers must be invited or claim via share code before DMs work.

GET  https://chat.wusper.com/api/v1/bot/me
GET  https://chat.wusper.com/api/v1/dm/peers
GET|POST https://chat.wusper.com/api/v1/dm/messages
GET  https://chat.wusper.com/api/v1/threads
GET|POST https://chat.wusper.com/api/v1/threads/<threadId>/messages

Realtime:WebSocket 即時進線

三種 API 金鑰都支援。連上後新訊息會立刻推送(不必只靠輪詢 GET)。Webhook 仍可用;可擇一或並用。 冪等/deduped 送訊不會再推一次。
wss://chat.wusper.com/api/v1/ws

認證

  • Header:Authorization: Bearer wc_…
  • 或 Query:?access_token=wc_…(瀏覽器/簡易客戶端)

範圍

金鑰會推什麼
private綁定私人房 message.created(尊重 @mention;不含自己送出的那把 key)
delegate擁有者參與且 ACL 開啟的 DM(同 key 自己 API 送出的不回聲)
bot進線 Bot DM、進線三人串(+若綁私人房);Bot 自己送的不回聲

另推 message.interaction 給送出 HTML 組件的那把 key。

連線 hello

{ "type": "hello", "key_id": "…", "key_type": "bot", "ts": 0 }

事件示例

{
  "type": "message.created",
  "channel": "dm",
  "key_id": "…",
  "key_type": "bot",
  "peer_user_id": "…",
  "message": { "id": "…", "body": "hi", "created_at": 0 }
}

channel:private_room|dm|thread。詳見 api-v1.md。

GET 訊息排序

所有讀訊息 GET 支援 order=oldest|newest(或 sort=asc|desc)。預設 oldest:最舊的 limit 筆、時間升序。newest:最新 limit 筆、時間降序。limit 預設 100、上限 200。

Realtime:WebSocket 即时进线

三种密钥均可连接 wss://chat.wusper.com/api/v1/ws(Bearer 或 ?access_token=)。事件与 webhook 同精神:message.created / message.interaction。GET 列表支持 order=oldest|newest(默认 oldest)。

Realtime WebSocket

All key types: wss://chat.wusper.com/api/v1/ws with Bearer or ?access_token=. Pushes message.created / message.interaction in-scope. Deduped sends are not re-broadcast. List GETs accept order=oldest|newest (default oldest).

Webhooks

私人對話金鑰與 Bot 可設 webhook_url(設置 → API → 管理)。有新訊息時,伺服器 POST JSON 到你的 URL。低延遲進線請優先用上方 Realtime WebSocket。

請求頭

  • Content-Type: application/json
  • User-Agent: WusperChat-Webhook/1.0
  • X-Wusper-Event — 例如 message.created
  • X-Wusper-Delivery — 投遞 ID
  • X-Wusper-Timestamp — Unix 秒
  • X-Wusper-Signature: sha256=<hmac_hex> — 若有 webhook secret:對原始 body 做 HMAC-SHA256

驗簽(Node 示意)

import crypto from 'node:crypto';
function ok(rawBody, secret, header) {
  const expect = 'sha256=' + crypto.createHmac('sha256', secret)
    .update(rawBody, 'utf8').digest('hex');
  return header === expect;
}

失敗會重試一次;設置頁可看投遞紀錄並重放。請回 2xx。

Webhooks

私人对话密钥与 Bot 可设 webhook_url。服务器 POST JSON;签名头 X-Wusper-Signature: sha256=…(HMAC-SHA256 原始 body)。

Webhooks

Optional on private / bot keys. Server POSTs JSON with X-Wusper-Event, X-Wusper-Delivery, X-Wusper-Timestamp, and X-Wusper-Signature: sha256=<hmac> over the raw body when a secret is set. Reply 2xx; one retry on failure.

安裝 SDK/套件

# JS / npm
npm install https://chat.wusper.com/api-packages/wusper-chat-sdk.tgz

# Python
pip install https://chat.wusper.com/api-packages/wusper_chat-0.1.0-py3-none-any.whl

# Linux .deb
curl -fsSL -O https://chat.wusper.com/api-packages/wusper-chat-sdk_0.1.0_all.deb
sudo apt install ./wusper-chat-sdk_0.1.0_all.deb

# 一包 zip(設置 → API → API package 下載)
# https://chat.wusper.com/api-packages/wusper-chat-api-packages.zip

預設客戶端 baseUrl 即為 https://chat.wusper.com。

安装 SDK/套件

npm install https://chat.wusper.com/api-packages/wusper-chat-sdk.tgz
pip install https://chat.wusper.com/api-packages/wusper_chat-0.1.0-py3-none-any.whl
curl -fsSL -O https://chat.wusper.com/api-packages/wusper-chat-sdk_0.1.0_all.deb
sudo apt install ./wusper-chat-sdk_0.1.0_all.deb

SDK install

npm install https://chat.wusper.com/api-packages/wusper-chat-sdk.tgz
pip install https://chat.wusper.com/api-packages/wusper_chat-0.1.0-py3-none-any.whl
# deb + zip also under /api-packages/

Default client base URL is https://chat.wusper.com.

限速與其它

  • 每個金鑰:每分鐘 60 次請求(滑動/視窗計數)。
  • 超限回傳錯誤;請退避後重試。
  • 原始 Markdown:/docs/api-v1.md · OpenAPI:/docs/openapi-v1.yaml

限速与其它

Rate limits

Delete records

DELETE /api/v1/messages/:id — body {"scope":"me"|"everyone","channel":"dm"|"private_room"|"thread"}. me hides for you; everyone tombstones (sender only for DM/thread).

DELETE /api/v1/conversations — clear history for you and hide from list (does not unfriend). Body kind + with / room_id / thread_id.

WS events: message.deleted, conversation.deleted on /api/v1/ws and session /api/ws.