Bluesky facets builder
Paste a Bluesky post and get every link, mention, and hashtag as a facet with its UTF-8 byte offsets, the post record to send with createRecord, and TypeScript that posts it.
Facets
112 of 300 characters (graphemes), 115 of 3,000 bytes, 3 facets.
-
Mention
@bsky.appbytes 40 to 49 (JavaScript index 38 to 47)
-
Link
https://example.com/changelogbytes 71 to 100 (JavaScript index 69 to 98)
-
Hashtag
#buildinpublicbytes 101 to 115 (JavaScript index 99 to 113)
The post record
Send this as the record of a
com.atproto.repo.createRecord call with the
app.bsky.feed.post collection. Replace each mention's
<DID of …> placeholder with the DID that
com.atproto.identity.resolveHandle returns for that handle, and set
createdAt to the time you post.
{
"$type": "app.bsky.feed.post",
"text": "Shipped v2 of our scheduler 🚀 thanks @bsky.app for the docs. Notes: https://example.com/changelog #buildinpublic",
"createdAt": "2026-12-01T12:00:00.000Z",
"facets": [
{
"index": {
"byteStart": 40,
"byteEnd": 49
},
"features": [
{
"$type": "app.bsky.richtext.facet#mention",
"did": "<DID of bsky.app>"
}
]
},
{
"index": {
"byteStart": 71,
"byteEnd": 100
},
"features": [
{
"$type": "app.bsky.richtext.facet#link",
"uri": "https://example.com/changelog"
}
]
},
{
"index": {
"byteStart": 101,
"byteEnd": 115
},
"features": [
{
"$type": "app.bsky.richtext.facet#tag",
"tag": "buildinpublic"
}
]
}
]
}
Post it from TypeScript
With Social SDK, you don't build link or hashtag facets yourself:
the Bluesky adapter adds them with the same rules this page uses, checks the
300-character and 3,000-byte limits, and creates the record. Mentions are the one
thing you pass in, as byte offsets with a resolved DID, because the SDK never looks
up a handle for you. The code follows the text above and uses the npm release 0.6.0.
One difference: for a URL quoted like “https://example.com”, 0.6.0 keeps
the closing quote in the link. This page leaves it out, as the SDK's source on GitHub
now does.
import { createSocial, connectedAccountRef } from "@opencoredev/social-sdk";
import { bluesky } from "@opencoredev/social-sdk/bluesky";
const identifier = process.env["BLUESKY_HANDLE"];
const password = process.env["BLUESKY_APP_PASSWORD"];
if (!identifier || !password) throw new Error("Set BLUESKY_HANDLE and BLUESKY_APP_PASSWORD");
// bsky.social serves accounts Bluesky hosts. For a self-hosted account, use its PDS URL.
const service = "https://bsky.social";
const login = await fetch(`${service}/xrpc/com.atproto.server.createSession`, {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ identifier, password }),
});
if (!login.ok) throw new Error(`Bluesky login failed with HTTP ${login.status}`);
const session: unknown = await login.json();
if (
typeof session !== "object" || session === null ||
!("did" in session) || typeof session.did !== "string" ||
!("accessJwt" in session) || typeof session.accessJwt !== "string"
) throw new Error("Unexpected createSession response");
const social = createSocial({
backend: bluesky({
auth: { service, did: session.did, accessJwt: session.accessJwt },
}),
});
const account = connectedAccountRef({ backend: "default", platform: "bluesky", accountId: session.did });
// Social SDK adds the link and hashtag facets itself, with UTF-8 byte offsets.
const text = "Shipped v2 of our scheduler 🚀 thanks @bsky.app for the docs. Notes: https://example.com/changelog #buildinpublic";
// A mention needs the account's DID. Resolve each handle before posting.
async function resolveHandle(handle: string): Promise<string> {
const url = new URL("https://public.api.bsky.app/xrpc/com.atproto.identity.resolveHandle");
url.searchParams.set("handle", handle);
const response = await fetch(url);
if (!response.ok) throw new Error(`Could not resolve @${handle}: HTTP ${response.status}`);
const body: unknown = await response.json();
if (typeof body !== "object" || body === null || !("did" in body) || typeof body.did !== "string")
throw new Error("Unexpected resolveHandle response");
return body.did;
}
// UTF-8 byte offsets of each @handle, from the facet builder.
const mentions = [
{ byteStart: 40, byteEnd: 49, did: await resolveHandle("bsky.app") },
];
const result = await social.posts.publish({
targets: [{ account, options: { mentions } }],
content: { text },
});
for (const outcome of result.outcomes) {
if (outcome.state === "published") console.log("published", outcome.post.native);
else console.log(outcome.state, outcome);
}
How the builder works
- Offsets are UTF-8 bytes. A facet's
byteStartandbyteEndcount bytes of the UTF-8 text, with an inclusive start and an exclusive end. JavaScript'sindexOfandslicecount UTF-16 code units, so they drift as soon as the text holds an emoji or an accented letter. Each facet above shows both, so you can see the gap. - Links are http:// and https:// URLs, without trailing punctuation or an unmatched closing parenthesis. A URL right after an opening quote usually ends at the matching closing quote, so
“https://example.com”links only the address and'https://example.com/it's'keeps the apostrophe init's. Straight quotes can be ambiguous, so check the link facet above when you quote a URL that way. Bluesky doesn't link a URL that has no link facet. - Hashtags start with # (or the full-width #) after whitespace or at the start of the text and need at least one character that isn't a digit or punctuation. Like the SDK, the builder skips a tag longer than 64 JavaScript characters, and a hashtag inside a link isn't tagged.
- Mentions are an @ followed by a full handle, which is a domain name such as alice.bsky.social. The facet stores the account's DID, not the handle, so resolve each handle before you post. Facets can't overlap.
- Length is counted in graphemes, what a reader sees as one character, so a family emoji is 1. A post holds 300 graphemes and must also fit in 3,000 UTF-8 bytes.
Bluesky documents facets in links, mentions, and rich text (read on 1 December 2026). For sessions, images, video, and rate limits, read the Bluesky API guide. To check one post against every platform's limits at once, use the post limits checker, and for the SDK's Bluesky options, see the Bluesky platform page.
Rather not run it yourself? Social SDK Cloud, the hosted version, is taking early-access signups. Join the list.