Base URL · https://chat.wusper.com
Bearer API 前綴一律是 /api/v1/…。設定頁的靜態文件/套件另見下方連結。
三種金鑰共用的路徑:
| 方法 | 完整 URL | 說明 |
|---|---|---|
GET | https://chat.wusper.com/api/v1/me | 查金鑰類型、擁有者、綁定房間/Bot |
GET↑WS | wss://chat.wusper.com/api/v1/ws | 三種金鑰即時進線(Bearer 或 ?access_token=) |
GET | https://chat.wusper.com/api/version | 版本與文件/套件路徑(無需 Bearer) |
① 私人對話(type: private,金鑰 wc_…)
| 方法 | 完整 URL | 說明 |
|---|---|---|
GET | https://chat.wusper.com/api/v1/private/messages?limit=50&order=newest | 讀取綁定私人房間訊息(order=oldest|newest,預設 oldest) |
POST | https://chat.wusper.com/api/v1/private/messages | 送訊/HTML/流式 · {"body"|"html"};加 stream:true 開流式 |
② 代管(type: delegate,金鑰 wc_…)
| 方法 | 完整 URL | 說明 |
|---|---|---|
GET | https://chat.wusper.com/api/v1/friends | 列出好友 |
GET | https://chat.wusper.com/api/v1/messages?with=<userId>&order=newest | 讀取與好友的 DM(需 ACL;可 order) |
POST | https://chat.wusper.com/api/v1/messages | 代帳號送 DM/HTML/流式 · {"to","body"|"html"};stream:true 開流式 |
③ Bot(type: bot,金鑰 wc_…;分享碼 wbot_… 不是 Bearer)
| 方法 | 完整 URL | 說明 |
|---|---|---|
GET | https://chat.wusper.com/api/v1/bot/me | Bot 資料 |
GET | https://chat.wusper.com/api/v1/dm/peers | 可私訊的對象 |
GET | https://chat.wusper.com/api/v1/dm/messages?with=<userId>&order=newest | 讀取與 peer 的 DM(可 order) |
POST | https://chat.wusper.com/api/v1/dm/messages | Bot 送 DM/HTML/流式 · {"to","body"|"html"};stream:true 開流式 |
GET | https://chat.wusper.com/api/v1/threads | 三人串列表 |
GET | https://chat.wusper.com/api/v1/threads/<threadId>/messages?order=newest | 讀取串訊息(可 order) |
POST | https://chat.wusper.com/api/v1/threads/<threadId>/messages | 送串/HTML/流式 · {"body"|"html"};stream:true 開流式 |
相關靜態資源:
https://chat.wusper.com/api-docshttps://chat.wusper.com/docs/openapi-v1.yamlhttps://chat.wusper.com/docs/api-v1.mdhttps://chat.wusper.com/api-packages/wusper-chat-api-packages.zipBearer API 前缀一律是 /api/v1/…。
三种密钥共用:
| 方法 | 完整 URL | 说明 |
|---|---|---|
GET | https://chat.wusper.com/api/v1/me | 查密钥类型、拥有者、绑定房间/Bot |
GET | https://chat.wusper.com/api/version | 版本与文档/套件路径(无需 Bearer) |
① 私人对话(type: private,密钥 wc_…)
| 方法 | 完整 URL | 说明 |
|---|---|---|
GET | https://chat.wusper.com/api/v1/private/messages?limit=50&order=newest | 读取绑定私人房间消息(order=oldest|newest,默认 oldest) |
POST | https://chat.wusper.com/api/v1/private/messages | 发送/HTML/流式 · {"body"|"html"};stream:true 开流式 |
② 代管(type: delegate,密钥 wc_…)
| 方法 | 完整 URL | 说明 |
|---|---|---|
GET | https://chat.wusper.com/api/v1/friends | 列出好友 |
GET | https://chat.wusper.com/api/v1/messages?with=<userId> | 读取与好友的 DM(需 ACL) |
POST | https://chat.wusper.com/api/v1/messages | 代账号发 DM/HTML/流式 · {"to","body"|"html", stream?:true} |
③ Bot(type: bot,密钥 wc_…;分享码 wbot_… 不是 Bearer)
| 方法 | 完整 URL | 说明 |
|---|---|---|
GET | https://chat.wusper.com/api/v1/bot/me | Bot 资料 |
GET | https://chat.wusper.com/api/v1/dm/peers | 可私信对象 |
GET | https://chat.wusper.com/api/v1/dm/messages?with=<userId> | 读取与 peer 的 DM |
POST | https://chat.wusper.com/api/v1/dm/messages | Bot 发 DM/HTML/流式 · {"to","body"|"html", stream?:true} |
GET | https://chat.wusper.com/api/v1/threads | 三人串列表 |
GET | https://chat.wusper.com/api/v1/threads/<threadId>/messages | 读取串消息 |
POST | https://chat.wusper.com/api/v1/threads/<threadId>/messages | 发送串/HTML/流式 · {"body"|"html", stream?:true} |
https://chat.wusper.com/api-docshttps://chat.wusper.com/docs/openapi-v1.yamlhttps://chat.wusper.com/docs/api-v1.mdhttps://chat.wusper.com/api-packages/wusper-chat-api-packages.zipBearer routes live under /api/v1/….
Common
| Method | Full URL | Notes |
|---|---|---|
GET | https://chat.wusper.com/api/v1/me | Key type, owner, bound room / bot |
GET | https://chat.wusper.com/api/version | Version + docs/package paths (no Bearer) |
① Private chat (type: private, secret wc_…)
| Method | Full URL | Notes |
|---|---|---|
GET | https://chat.wusper.com/api/v1/private/messages?limit=50 | List bound private-room messages |
POST | https://chat.wusper.com/api/v1/private/messages | Send text/HTML/stream · {"body"|"html"}; stream:true starts stream |
② Delegate / managed (type: delegate, secret wc_…)
| Method | Full URL | Notes |
|---|---|---|
GET | https://chat.wusper.com/api/v1/friends | List friends |
GET | https://chat.wusper.com/api/v1/messages?with=<userId> | DM history (ACL required) |
POST | https://chat.wusper.com/api/v1/messages | Send as owner · {"to","body"|"html"}; stream:true starts stream |
③ Bot (type: bot, secret wc_…; share code wbot_… is NOT Bearer)
| Method | Full URL | Notes |
|---|---|---|
GET | https://chat.wusper.com/api/v1/bot/me | Bot profile |
GET | https://chat.wusper.com/api/v1/dm/peers | DM-capable peers |
GET | https://chat.wusper.com/api/v1/dm/messages?with=<userId> | DM history |
POST | https://chat.wusper.com/api/v1/dm/messages | Send DM · {"to","body"|"html"}; stream:true starts stream |
GET | https://chat.wusper.com/api/v1/threads | Group-of-3 threads |
GET | https://chat.wusper.com/api/v1/threads/<threadId>/messages | Thread history |
POST | https://chat.wusper.com/api/v1/threads/<threadId>/messages | Send text/HTML/stream · {"body"|"html"}; stream:true |
三種 API 金鑰的秘密字串都以 wc_ 開頭。請求時放在 Authorization:
Authorization: Bearer wc_YOUR_SECRET
Content-Type: application/json
Accept: application/json
wbot_…,只用於在 UI 把 Bot 加成好友/認領,不能當 Bearer。body;私人房間亦接受別名 text)。{"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)關閉回報。"stream": true(缺省/false=一次送完)。之後 POST …/messages/:id/chunks → …/complete。…/messages/stream 為別名。流式時 HTML 照常接受並顯示,但按鈕互動不適用(回傳 warning: "html_components_unavailable_while_streaming",interact 強制 false)。三种 API 密钥的秘密字符串都以 wc_ 开头。请求时放在 Authorization:
Authorization: Bearer wc_YOUR_SECRET
Content-Type: application/json
Accept: application/json
wbot_…,只用于在 UI 把 Bot 加成好友/认领,不能当 Bearer。body)。{"html":"…"};用户点击按钮会 webhook message.interaction 回发送方 API(含 message_id、element id/label)。也可 GET /api/v1/interactions。"stream": true(缺省/false=一次发完)。随后 chunks → complete。流式时 HTML 照常接收显示,但按钮互动不适用(警告 html_components_unavailable_while_streaming)。All three API secrets start with wc_. Send:
Authorization: Bearer wc_YOUR_SECRET
Content-Type: application/json
Accept: application/json
wbot_…) are for friend-claim in the UI — not Bearer tokens.body).{"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."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).wbot_ 分享碼加人;可設 Webhook、三人串。wc_… 秘密;關掉後無法再看(只能重新產生)。wc_… 秘密;关掉后无法再看(只能重新生成)。wc_… secret (shown once).用途:把一個房間當「頻道/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
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
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');
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
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
用途:自動化你自己的帳號(客服腳本、橋接等)。每個要操作的好友必須在 設置 → API → 管理該金鑰 開啟對應 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&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
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。Bearer 仍是 wc_…。分享碼 wbot_… 給別人在 App 內認領/加好友用。Peer 需擁有者邀請或分享碼認領後,才能用 DM 路徑互通。
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
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
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"
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
Authorization: Bearer wc_…?access_token=wc_…(瀏覽器/簡易客戶端)| 金鑰 | 會推什麼 |
|---|---|
private | 綁定私人房 message.created(尊重 @mention;不含自己送出的那把 key) |
delegate | 擁有者參與且 ACL 開啟的 DM(同 key 自己 API 送出的不回聲) |
bot | 進線 Bot DM、進線三人串(+若綁私人房);Bot 自己送的不回聲 |
另推 message.interaction 給送出 HTML 組件的那把 key。
{ "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 支援 order=oldest|newest(或 sort=asc|desc)。預設 oldest:最舊的 limit 筆、時間升序。newest:最新 limit 筆、時間降序。limit 預設 100、上限 200。
三种密钥均可连接 wss://chat.wusper.com/api/v1/ws(Bearer 或 ?access_token=)。事件与 webhook 同精神:message.created / message.interaction。GET 列表支持 order=oldest|newest(默认 oldest)。
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).
私人對話金鑰與 Bot 可設 webhook_url(設置 → API → 管理)。有新訊息時,伺服器 POST JSON 到你的 URL。低延遲進線請優先用上方 Realtime WebSocket。
Content-Type: application/jsonUser-Agent: WusperChat-Webhook/1.0X-Wusper-Event — 例如 message.createdX-Wusper-Delivery — 投遞 IDX-Wusper-Timestamp — Unix 秒X-Wusper-Signature: sha256=<hmac_hex> — 若有 webhook secret:對原始 body 做 HMAC-SHA256import 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。
私人对话密钥与 Bot 可设 webhook_url。服务器 POST JSON;签名头 X-Wusper-Signature: sha256=…(HMAC-SHA256 原始 body)。
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.
# 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。
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
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.
/docs/api-v1.md · OpenAPI:/docs/openapi-v1.yaml/docs/api-v1.md · OpenAPI:/docs/openapi-v1.yamlDELETE /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.