Bluesky nowplaying bots

Automated BBC Radio accounts posting the currently playing track to Bluesky.

Made with: Val Town, Turso, Bluesky API, BBC music data

What are they and how do they work?

These are my oldest kinds of bots. I ran the first 6 Music nowplaying bot on Twitter (in 2012!), then moved to Bluesky when free API access was turned off. I initially hosted them on Digital Ocean, then on Glitch for a while, then moved them to Val Town when Glitch closed down.

Each bot, like @6music.bsky.social, runs as a small Val Town script on a cron job every 10 minutes. When it starts, it resumes a saved Bluesky session from a SQLite database, fetches the current track from the BBC data feed, and builds a #nowplaying post for that station.

While the Val is running, it checks the feed every 15 seconds and compares the current track with a local in-memory cache. Only when the track has changed does it try to post, with a quick check of the bot's recent Bluesky feed as a second duplicate guard.

Environment variables

Each scheduled Val Town bot uses a small set of environment variables so the same script can be reused for different BBC stations and Bluesky accounts.

BLUESKY_SHORTNAME
The bot key used to find the right row in the database and build the hashtag, for example 6music.
BLUESKY_USERNAME
The Bluesky account identifier the bot logs in as.
BLUESKY_PASSWORD
The Bluesky app password used when a saved session cannot be resumed.
BBC_DATA_URL
The BBC endpoint for the station's currently playing music data.
TURSO_DATABASE_URL
The database URL that stores each bot's session and latest posted track.
TURSO_AUTH_TOKEN
The auth token used to read and update the bot state.

The database

There's not much to it: a single SQLite table with one row per bot, storing the bot name, the saved Bluesky session JSON, and the latest post text used for duplicate detection.

Example SQLite state table
id integer bot_name text session_json text latest_post text
1 6music {"did":"did:plc:cl7lgkeo..."} “Beautiful (feat. Pharre...”
2 1xtra {"handle":"radio1xtra.bs..."} “Folded” by Kehlani #now...
3 radio1 {"handle":"radio-1.bsky..."} “I Only Smoke When I Dri...
4 radio2 {"handle":"radio2.bsky.s..."} “Street Of Dreams” by U2...
5 radio3 {"handle":"radio3.bsky.s..."} “Symphony No. 3 in F Maj...

Nowplaying bots