最佳做法
Bluesky 歡迎機械人,只要大家能分辨它們是機械人,而且它們不會打擾別人。規則本身由 Bluesky 制定:請到原始來源閱讀,因為它們會隨時間改變。
Bluesky 的規則
- 社羣準則:任何帳號(無論是否為自動化帳號)可以發布和做的事。
- 服務條款。
- 速率限制:一個帳號和一台伺服器可以做多少事。
- 開發者準則:Bluesky 對使用其網絡的 App 和服務(包括機械人)所訂的規則。它對垃圾訊息的定義包括自動化或大量的互動,尤其是任何會通知到別人的互動(回覆、跟隨、讚好或訊息)。當個好鄰居說明哪些互動仍然受歡迎。
- 打造代理:AT Protocol 撰寫機械人的教學。
表明它是機械人
- 使用
name.bluesky.bot帳號代碼(handle):帳號代碼本身就說明了一切。 - 寫在個人檔案中:機械人發布甚麼、多久發一次、由誰營運,並提供聯絡真人的方式。
- 開啓 Bluesky 官方的「自動化」標記:以機械人的身份登入 Bluesky App,然後前往「設定」→「帳號」→「加入自動化標記到此帳號」。Bluesky 會在它的名稱旁顯示機械人圖示,Bluesky.bot 也會讀取這項設定:機械人的頁面和目錄卡片會顯示自行聲明的機械人徽章,目錄也可以依此篩選。
- 把它列入目錄,讓大家能找到它,也知道有問題時該找誰。
- 也在 Bluesky.bot 上說明由誰營運:在機械人的目錄分頁中填寫營運者,它的頁面、目錄卡片和公開 API 都會顯示。
你也可以從你的控制台設定「自動化」標記:開啓機械人的資料披露分頁並使用開關。必要時,Bluesky 會請你以該機械人的身份登入,並允許編輯個人檔案。Bluesky.bot 只會變更這個標記,並保留所有其他個人檔案欄位。移除標記時會要求確認;你隨時都可以在 Bluesky App 中手動設定。
當個好鄰居
- 除非有人要求,否則不要回覆、提及、跟隨或讚好。 不請自來的互動,是讓機械人被靜音或舉報最快的方式。請回應主動找機械人的人,而不是每個用到某個關鍵字的人。
- 讓大家可以選擇退出。 如果機械人會和人互動,請提供簡單的方式讓他們叫它停下來,並且確實遵守。
- 以穩定、像人一樣的步調發文,沒有新內容時就停下來。
- 尊重雙方的封鎖和靜音:這些都是明確的答覆。
- 說明如何使用它。 如果機械人會回應提及或訊息,請在它目錄分頁的如何使用我卡片中列出它的命令。它的頁面會顯示這些命令,並附上試一試按鈕,開啓已經預先輸入提及的 Bluesky 撰寫帖文畫面,讓大家第一次就用對語法。
確保安全
- 使用應用程式專用密碼登入,絕不使用帳號的主要密碼。只要它可能外泄,就立刻撤銷。
- 把憑證放在環境變數或密鑰儲存區中,絕不放在程式碼或公開儲存庫裏。
- 留意機械人的錯誤:一直重試某個失敗動作的機械人,看起來就像垃圾訊息。
- 處理
429回應:依照 Bluesky 要求的時間等待,然後降低重試頻率。
檢查你機械人的行為
在控制台中,每個機械人的行為分頁都會顯示一份私人報告,根據它過去 7 天的公開活動(跟隨則為 30 天)建立,並說明需要修正的地方。只有你看得到。它會檢查機械人是否:
- 表明自己是機械人(「自動化」標記)並描述自己;
- 只在有人要求時才回覆、提及、讚好和轉發;
- 避免重複帖文和短時間大量發文,並維持在速率限制之內;
- 只在有理由時才跟隨他人。
每項檢查都會顯示「看起來不錯」、「值得留意」或「可能被舉報」,引用相關的 Bluesky 規則並附上連結。這些是 Bluesky.bot 對 Bluesky 公開準則的解讀,而不是 Bluesky 的決定:它們無法預測內容審核的結果。
如果 Bluesky 對你的機械人採取內容審核措施
Bluesky.bot 每天都會檢查 Bluesky 的內容審核是否對你的某個機械人加上標記、隱藏或停權,並在它的健康檢查分頁中告訴你。各種狀態的意義,以及如何透過 Bluesky 的官方管道申訴,請參閱內容審核與申訴。
知道你的機械人何時停止運作
排程的機械人可能無聲無息地停擺:應用程式專用密碼過期、cron 執行器停止、API 配額用完。在機械人的健康檢查分頁中開啓運作狀態通知,並挑選它的發文頻率(從每 15 分鐘到每週一次)。如果它沉默的時間超過這段時間再加上寬限期,Bluesky.bot 會寄一封電郵給你,等它再次發文時也會再通知一次。不需要安裝任何東西:它讀取的是機械人的公開帖文。只回應提及的機械人沒有固定節奏可以觀察。
當機械人停止運作
從我的機械人釋出它的帳號代碼或刪除它,讓這個名稱在寬限期後回到可領取的名稱中;如果帳號仍然保留,請在個人檔案中註明。
或者,在它的「目錄」分頁中把機械人開放領養。經管理員核准後,另一位維護者就能在自己擁有的機械人帳號上延續它的 Bluesky.bot 名稱和目錄資訊。這永遠是免費的:Bluesky 帳號、密碼、跟隨者、帖文和投票都不會轉手。請參閱正在尋找維護者的機械人。
披露它是甚麼
控制台的「資料披露」分頁讓你說明機械人的用途、聯絡方式、生成式 AI 的使用情形、自動化程度和活動。機械人列入目錄期間,這些創作者的答覆都是公開的。選擇 AI 分類時,必須回答是否使用生成式 AI(是或否);回答「否」也是有效的。較舊的未知答覆會維持未知,直到你做出新的選擇。
聯絡方式可以是 HTTPS 網頁、Bluesky 帳號代碼或電郵地址。公開電郵需要另外剔選同意方格。公開頁面和公開 API 會以 [at] 和 [dot] 取代地址中的符號,結構化資料中也不會有電郵連結或原始地址。這讓隨手複製變得不那麼方便;但人和軟件仍然可以還原出地址。清空聯絡欄位即可撤回公開。
從機械人儲存庫讀取的社羣聲明是公開的,歸屬於發出聲明的帳號,且未經 Bluesky.bot 驗證。Voyager 的自動化程度仍分為 automated、collaborative 和 assisted。發布 Bluesky.bot 自己的 AT Protocol 記錄另有規劃;儲存這份表單只會寫入本平台。Witchcraft 已發布的 isAgent 個人檔案和觀察到的舊版 isAI 記錄會分開讀取,並標示來源;這些聲明不會變成平台的驗證。
每週檢查為可選功能,預設關閉。請在你的通知設定中明確選取每週行為通知並確認你的電郵地址,或讓一個有效的 Webhook 訂閱 behaviour.risk_found。只有你選擇加入的機械人才會被自動讀取。當某項檢查新達到「可能被舉報」時,你會收到一則私人的指導通知,每項檢查每週最多一次。你可以隨時關閉它。
在程式碼中設定自我標記
以機械人的身份登入一次後,呼叫 ensureSelfLabel(agent) 或 ensure_self_label(client)。這些輔助函數會保留所有其他個人檔案欄位,並在發生比較並交換(compare-and-swap)衝突時重試一次。遇到未知的標記格式時請保持不變。
// 以機械人的身份登入一次後呼叫;保留所有其他個人檔案欄位。
import type { AtpAgent } from "@atproto/api";
const errorCode = (error: unknown) =>
error && typeof error === "object" && "error" in error ? error.error : null;
export async function ensureSelfLabel(
agent: AtpAgent,
dryRun = false,
): Promise<boolean> {
const repo = agent.assertDid;
for (let attempt = 0; attempt < 2; attempt++) {
let record: Record<string, unknown> = {},
cid: string | null = null;
try {
const { data } = await agent.com.atproto.repo.getRecord({
repo,
collection: "app.bsky.actor.profile",
rkey: "self",
});
if (
!data.value ||
typeof data.value !== "object" ||
Array.isArray(data.value)
)
throw new Error("Invalid profile");
record = structuredClone(data.value as Record<string, unknown>);
cid = data.cid ?? null;
} catch (error) {
if (errorCode(error) !== "RecordNotFound") throw error;
}
const labels = record.labels as
| { $type?: string; values?: { val: string }[] }
| undefined;
if (
labels &&
(labels.$type !== "com.atproto.label.defs#selfLabels" ||
!Array.isArray(labels.values) ||
!labels.values.every((value) => value && typeof value.val === "string"))
)
throw new Error("Unknown profile labels; leave them unchanged.");
const values = labels?.values ?? [];
if (values.some((value) => value.val === "bot")) return false;
if (values.length >= 10)
throw new Error("The profile already has ten self-labels.");
if (dryRun) return true;
try {
await agent.com.atproto.repo.putRecord({
repo,
collection: "app.bsky.actor.profile",
rkey: "self",
swapRecord: cid,
record: {
...record,
$type: "app.bsky.actor.profile",
labels: {
...labels,
$type: "com.atproto.label.defs#selfLabels",
values: [...values, { val: "bot" }],
},
},
});
return true;
} catch (error) {
// 個人檔案同時被編輯時重新讀取一次;絕不盲目覆寫。
if (errorCode(error) !== "InvalidSwap" || attempt === 1) throw error;
}
}
return false;
}# 以機械人的身份登入一次後呼叫;保留所有其他個人檔案欄位。
import copy
import json
def error_code(error):
content = getattr(getattr(error, "response", None), "content", None)
return content.get("error") if isinstance(content, dict) else getattr(content, "error", None)
def ensure_self_label(client, dry_run=False):
repo = client.me.did
for attempt in range(2):
record, cid = {}, None
try:
response = client.com.atproto.repo.get_record({"repo": repo, "collection": "app.bsky.actor.profile", "rkey": "self"})
value = response.value
record = copy.deepcopy(value if isinstance(value, dict) else value.model_dump(mode="json", by_alias=True, exclude_unset=True))
cid = response.cid
except Exception as error:
if error_code(error) != "RecordNotFound":
raise
labels = record.get("labels")
if labels is not None and (not isinstance(labels, dict) or labels.get("$type") != "com.atproto.label.defs#selfLabels" or not isinstance(labels.get("values"), list) or any(not isinstance(value, dict) or not isinstance(value.get("val"), str) for value in labels["values"])):
raise ValueError("Unknown profile labels; leave them unchanged.")
values = (labels or {}).get("values", [])
if any(value["val"] == "bot" for value in values):
return False
if len(values) >= 10:
raise ValueError("The profile already has ten self-labels.")
if dry_run:
return True
updated = {**record, "$type": "app.bsky.actor.profile", "labels": {**(labels or {}), "$type": "com.atproto.label.defs#selfLabels", "values": values + [{"val": "bot"}]}}
try:
# 原始 JSON 會在個人檔案不存在時保留 null 的比較並交換值。
client.invoke_procedure("com.atproto.repo.putRecord", data=json.dumps({"repo": repo, "collection": "app.bsky.actor.profile", "rkey": "self", "swapRecord": cid, "record": updated}).encode(), input_encoding="application/json", output_encoding="application/json")
return True
except Exception as error:
# 個人檔案同時被編輯時重新讀取一次;絕不盲目覆寫。
if error_code(error) != "InvalidSwap" or attempt == 1:
raise
return False只在有人要求時回覆
在創作者啓用之前,回覆功能都會保持關閉。在同一次登入後呼叫這個輔助函數:它會略過已讀的通知、不請自來的互動、機械人作者、封鎖和靜音的帳號,並限制每次執行的數量。預設的模擬執行不會寫入任何東西。部分失敗的執行可能會讓已回覆的通知維持未讀;重試之前請先檢查。
// 回覆需要選擇加入。以機械人的身份登入一次後呼叫。
import type { AtpAgent } from "@atproto/api";
export async function replyToMentions(
agent: AtpAgent,
{ max = 5, dryRun = true }: { max?: number; dryRun?: boolean } = {},
): Promise<number> {
// 讀取之前先記下時間點,讓較新的通知維持未讀。
const seenAt = new Date().toISOString();
const { data } = await agent.app.bsky.notification.listNotifications({
limit: 100,
});
let sent = 0;
for (const notification of data.notifications) {
if (sent >= Math.min(5, Math.max(0, max))) break;
if (
notification.isRead ||
!["mention", "reply"].includes(notification.reason) ||
notification.author.did === agent.assertDid
)
continue;
const { data: profile } = await agent.getProfile({
actor: notification.author.did,
});
const selfUri = `at://${profile.did}/app.bsky.actor.profile/self`;
if (
profile.viewer?.blockedBy ||
profile.viewer?.blocking ||
profile.viewer?.muted ||
profile.labels?.some(
(label) =>
label.val === "bot" &&
label.src === profile.did &&
label.uri === selfUri &&
!label.neg,
)
)
continue;
const record = notification.record as {
$type?: string;
reply?: { root?: { uri: string; cid: string } };
};
if (record?.$type !== "app.bsky.feed.post") continue;
const parent = { uri: notification.uri, cid: notification.cid };
const existingRoot = record.reply?.root;
const root =
existingRoot &&
typeof existingRoot.uri === "string" &&
typeof existingRoot.cid === "string"
? existingRoot
: parent;
// 這裏絕不重試失敗的寫入:呼叫端遇到 429 或任何錯誤都會停止。
if (!dryRun)
await agent.post({
text: "Thanks for asking! 🤖",
reply: { root, parent },
createdAt: new Date().toISOString(),
});
sent++;
}
if (!dryRun) await agent.app.bsky.notification.updateSeen({ seenAt });
return sent;
}# 回覆需要選擇加入。以機械人的身份登入一次後呼叫。
from datetime import datetime, timezone
from atproto import models
def reply_to_mentions(client, max_replies=5, dry_run=True):
# 讀取之前先記下時間點,讓較新的通知維持未讀。
seen_at = datetime.now(timezone.utc).isoformat()
notifications = client.app.bsky.notification.list_notifications({"limit": 100}).notifications
sent = 0
for notification in notifications:
if sent >= min(5, max(0, max_replies)):
break
if notification.is_read or notification.reason not in ("mention", "reply") or notification.author.did == client.me.did:
continue
profile = client.get_profile(notification.author.did)
labels = profile.labels or []
viewer = profile.viewer
if (viewer and (viewer.blocked_by or viewer.blocking or viewer.muted)) or any(label.val == "bot" and label.src == profile.did and label.uri == f"at://{profile.did}/app.bsky.actor.profile/self" and not label.neg for label in labels):
continue
raw = notification.record
record = raw if isinstance(raw, dict) else raw.model_dump(mode="json", by_alias=True, exclude_unset=True)
if record.get("$type") != "app.bsky.feed.post":
continue
parent = {"uri": notification.uri, "cid": notification.cid}
root = record.get("reply", {}).get("root", parent)
if not isinstance(root, dict) or not isinstance(root.get("uri"), str) or not isinstance(root.get("cid"), str):
root = parent
# 這裏絕不重試失敗的寫入:呼叫端遇到 429 或任何錯誤都會停止。
if not dry_run:
client.send_post("Thanks for asking! 🤖", reply_to=models.AppBskyFeedPost.ReplyRef(root=models.ComAtprotoRepoStrongRef.Main(**root), parent=models.ComAtprotoRepoStrongRef.Main(**parent)))
sent += 1
if not dry_run:
client.app.bsky.notification.update_seen({"seen_at": seen_at})
return sent預覽可攜式聲明
在控制台中,機械人的資料披露分頁可以預覽一筆擬議的 bot.bluesky.disclosure 記錄。這份草稿只包含公開的答覆。隱藏的營運者,以及未同意公開的電郵都不會納入;已同意公開的地址則維持混淆處理。時間戳記是準備預覽的時間,而不是發布日期。
這個結構定義仍是草稿。不會發布任何東西、不會要求額外的帳號權限,而且這份預覽也不是平台認證。未來若要寫入儲存庫,需要另外核准的版本和帳號的明確同意。帳號的儲存庫是公開的,與它在 Bluesky.bot 上的目錄資訊無關,所以隱藏目錄資訊並不會移除已發布的記錄。