Automatically post to BlueSky

Since the 2024 election, the BlueSky social network has exploded in popularity, and appears to be replacing the cesspool that used to be Twitter. I'm not much of a social media person -- I much prefer hanging out in smaller spaces with people with shared interests. If you're like me, I would highly recommend finding a Mastodon server that caters to your interests, where you're sure to find rewarding conversations.

That said, if you're trying to reach the much broader Internet, BlueSky might be worth a try.

When I made the automation to post to Mastodon, I wanted to post to BlueSky at the same time. But it turns out it's not quite as easy to do. There's an authentication handshake that's tricky to do without a library, the data payload has an extra layer, and posting images also not so straightforward. I couldn't quickly do it just with the Events, Conditions, and Actions (ECA) module like I could with Mastodon, and I couldn't find any Drupal module to make this work.

So I created one.

Introducing the BlueSky Integration Drupal Module

Now, if you use ECA on Drupal, posting to BlueSky just got a whole lot easier. Install the BlueSky Integration module like any other module, and you'll find actions to send messages to BlueSky.

You do need to create an "App Password" on your BlueSky account, and configure the module with your Bsky handle. The app password goes into the "Key" module, which provides a way to safely store secrets in Drupal outside the code or configuration (but you can store it in configuration to get started).

Once that's set, you use the "Create Post" action in ECA to create a post, and then "Send Post" to actually send it to BlueSky. You can also "Add Facets", which is necessary to have BlueSky make your links clickable, and "Add Image" to add an image to your post

There is a gotcha for images -- BlueSky won't accept them if they are bigger than 1 MB. And I ran into an issue trying to send an image using an image style to scale it down to size -- if you use the "path" or "URI" of the image, Drupal may not have generated it when you attach it, so you get an error. If you use the "URL" version, it doesn't load.

So what I did was set the image to the URI version, and added that to a queue with a 30 second delay. And then I used the http request action to request the URL version of the image with the chosen style. This made ECA go fetch the image, which caused it to get generated. And then later when the queue job runs, the image exists. And then I set the frequency of my cron job to run every 5 minutes instead of every hour.

Add new comment

The content of this field is kept private and will not be shown publicly.

Filtered HTML

  • Web page addresses and email addresses turn into links automatically.
  • Allowed HTML tags: <a href hreflang> <em> <strong> <blockquote cite> <cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h1> <h2 id> <h3 id> <h4 id> <h5 id> <p> <br> <img src alt height width>
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.