規格指南
涵蓋註冊、同步、房間操作與 bot 指令傳遞的簡明 API 指南。
API 參考
ECCP 讓線上契約保持明確。客戶端透過受驗證的 API 與 homeserver 溝通,而聯邦流量則保留在伺服器對伺服器的平面。
Client 介面
| 方法 | 端點 | 用途 |
| --- | --- | --- |
| POST | /_eccp/client/v1/register | 建立帳號與初始裝置 |
| POST | /_eccp/client/v1/login | 換取具範圍限制的 token |
| POST | /_eccp/client/v1/rooms | 建立私訊、群組或 Shadow Room |
| PUT | /_eccp/client/v1/rooms/{roomId}/send/{eventType} | 傳送房間事件 |
| GET | /_eccp/client/v1/sync | 漸進同步帳號資料與時間線 |
Bot 介面
| 方法 | 端點 | 用途 |
| --- | --- | --- |
| POST | /_eccp/bot/v1/commands | 傳遞 slash command |
| POST | /_eccp/bot/v1/webhooks/{webhookId} | 注入被允許的 bot 事件 |
指令請求範例
TypeScript snippet
TypeScript
interface CommandRequest {
command: "/translate" | "/todo" | "/remind";
roomId: string;
arguments: string[];
}
export async function sendCommand(
baseUrl: string,
accessToken: string,
payload: CommandRequest
): Promise<Response> {
return fetch(`${baseUrl}/_eccp/bot/v1/commands`, {
method: "POST",
headers: {
Authorization: `Bearer ${accessToken}`,
"Content-Type": "application/json"
},
body: JSON.stringify(payload)
});
}錯誤語義
ECCP 回應應同時提供穩定的機器可讀 errcode 與人類可讀 error。客戶端應根據 errcode 分支,而不是根據顯示文字判斷。