DEV Community

How I Built a $0 Bluesky Auto-Poster in Python (AT Protocol, Link Facets & 300-Grapheme Guard)

If you are building a side project or selling a $12 digital toolkit, Bluesky is currently one of the highest-signal platforms for developers and indie hackers - and unlike X's paid API tiers, Bluesky's AT Protocol API is completely free.

When I wired Bluesky into my GitHub Actions daily publishing pipeline, I ran into two subtle gotchas that break naive scripts:

  • URLs aren't clickable automatically unless you attach UTF-8 byte-offset facets.
  • The 300-grapheme hard limit will reject your entire post with HTTP 400 InvalidRequest and stall your queue if a single post + expanded URL goes over 300 characters.

Here is the exact, battle-tested Python pattern I use in production (running at $0/month on GitHub Actions).

Step 1: Authenticate with an App Password

Never use your main Bluesky password in automation. Create an App Password under Settings → Privacy & Security → App Passwords, then request a session JWT:

import requests
sess = requests.post(
    "https://bsky.social/xrpc/com.atproto.server.createSession",
    json={"identifier": BSKY_HANDLE, "password": BSKY_APP_PASSWORD},
    timeout=20,
).json()
did = sess["did"]
jwt = sess["accessJwt"]

Step 2: Build UTF-8 Byte-Offset Link Facets

AT Protocol calculates link positions in UTF-8 bytes, not Python string character indices. If your post includes emojis (👇, ❌) or CJK characters, using match.start() directly will highlight the wrong characters.

import re
def build_link_facets(text: str):
    facets = []
    for match in re.finditer(r"https?://[^\s]+", text):
        url = match.group(0)
        byte_start = len(text[:match.start()].encode("utf-8"))
        byte_end = byte_start + len(url.encode("utf-8"))
        facets.append({
            "index": {"byteStart": byte_start, "byteEnd": byte_end},
            "features": [{"$type": "app.bsky.richtext.facet#link", "uri": url}],
        })
    return facets

Step 3: Add a 300-Grapheme Guard (Preserving Your CTA Link)

A real bug I hit in production: a 280-character draft expanded to 341 characters once {{SITE_URL}} was injected, causing 4 consecutive scheduled runs to fail with grapheme too big. Adding a small truncation guard that protects the trailing URL guarantees the queue never stalls again:

def truncate_for_bluesky(text: str, limit: int = 300) -> str:
    if len(text) <= limit:
        return text
    url_match = re.search(r"https?://[^\s]+$", text.strip())
    if url_match:
        url = url_match.group(0)
        prefix = text[:url_match.start()].rstrip()
        allowed = limit - len(url) - 2
        if allowed > 20:
            return f"{prefix[:allowed].rstrip()}…\n{url}"
    return text[:limit - 1].rstrip() + "…"

Step 4: Shift GitHub Actions Cron Off :00

One bonus lesson: scheduling GitHub Actions at 0 1 * * * or 0 13 * * * puts your job in the worst global top-of-the-hour queue (often delaying execution by 8+ hours). Shifting to an off-peak minute like 17 1 * * * and 17 13 * * * makes your daily schedule dramatically more reliable.

Want the Complete $0 Auto-Publishing System?

I packaged the full working GitHub Actions + Python auto-publisher (Dev.to, Bluesky, Threads), 30-day Evergreen JSON queue, 20 battle-tested AI prompts, and 30 viral opening hooks into one bilingual toolkit:

  • 👉 AI Solo Creator Toolkit v2.0 - $12 on Gumroad
  • 👉 Live Demo & Free $0 Starter Pack
Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.