Skip to main content

Bots

Bots are accounts on the network that post automatically. Popular ones include bots that post the magnitude of recent earthquakes, photos from an archive on a regular schedule, etc.

You can skip the below tutorial and find the full starter script here.

Starter Template

Here's a TypeScript script that creates a bot that posts a smiley emoji on an automated schedule once every three hours.

Getting Started

Install TypeScript and Node.

npm i -g typescript
npm i -g ts-node

Then, save your bot's username and password to a .env file.

BLUESKY_USERNAME=
BLUESKY_PASSWORD=

Create a Script

The below script will post 🙂 every three hours.

import { BskyAgent } from '@atproto/api';
import * as dotenv from 'dotenv';
import { CronJob } from 'cron';
import * as process from 'process';

dotenv.config();

// Create a Bluesky Agent
const agent = new BskyAgent({
service: 'https://bsky.social',
})


async function main() {
await agent.login({ identifier: process.env.BLUESKY_USERNAME!, password: process.env.BLUESKY_PASSWORD!})
await agent.post({
text: "🙂"
});
console.log("Just posted!")
}

main();


// Run this on a cron job
const scheduleExpressionMinute = '* * * * *'; // Run once every minute for testing
const scheduleExpression = '0 */3 * * *'; // Run once every three hours in prod

const job = new CronJob(scheduleExpression, main); // change to scheduleExpressionMinute for testing

job.start();

Deploying Your Bot

You can deploy a simple bot for no or low cost on a variety of platforms, such as Heroku or Fly.io.

Rate Limits & Respecting Other Users

Keep in mind that bots should respect the network's rate limits. Automated bots that post to an account on an regular interval are welcome. If your bot interacts with other users, please only interact (like, repost, reply, etc.) if the user has tagged the bot account. It must be an opt-in interaction, or else your bot may be taken for spam.