DEV Community

Cover image for Posting to Bluesky Programmatically with the AT Protocol
Theodore Kelechukwu Onyejiaku
Theodore Kelechukwu Onyejiaku

Posted on Originally published at mystite.com

Posting to Bluesky Programmatically with the AT Protocol

Blue sky with clouds

Posting to Bluesky Programmatically with the AT Protocol

Bluesky is built on the AT Protocol, and the official @atproto/api package makes posting straightforward.

Install

npm install @atproto/api
Enter fullscreen mode Exit fullscreen mode

Log in and post

import { AtpAgent, RichText } from '@atproto/api';

const agent = new AtpAgent({ service: 'https://bsky.social' });
await agent.login({ identifier: 'you.bsky.social', password: process.env.BSKY_APP_PASSWORD });

const rt = new RichText({ text: 'New post: https://mystite.com/my-article' });
await rt.detectFacets(agent);
await agent.post({ text: rt.text, facets: rt.facets });
Enter fullscreen mode Exit fullscreen mode

Tips

  • Use an app password, not your main password.
  • Posts are limited to 300 characters — share a teaser plus a link.
  • detectFacets turns URLs and mentions into clickable links.

Top comments (0)