In my previous blog Automate Posting on Bluesky, I discussed how to use Power Automate to post on Bluesky using their API. Today, we’re taking it a step further by adding links and hashtags to your Bluesky content.
Before we begin
If you haven’t read my previous blog, I recommend starting there. It covers the essentials of posting to Bluesky, including generating a token using an HTTP action and parsing it with the Parse JSON action. Having a valid token is a requirement for creating posts through the Bluesky API.
To add links and hashtags to your posts, first follow the guidance in Automate Posting on Bluesky to get up and running. Once done, you can enhance your content using the info in this article.
Introducing Facets
This is the Bluesky post we’ll be creating. It’s virtually the same content as I generated in Automate Posting on Bluesky, but it now contains a link and hashtag.
To embed links and hashtags, Bluesky uses a feature called facets, a component of the Authenticated Transfer Protocol (AT Protocol). Facets let you define, link, and represent specific content types, enabling rich, interactive posts.
The Process in Action
Here’s how to employ the HTTP action to create the above post with working links and hashtags. The Method, URI and headers are the same as used in my previous post Automate Posting on Bluesky. Only the JSON payload is different.
The “byteStart” and “byteEnd” keys in each object in the facet’s array, indicate the start and end positions (in bytes) of the link or hashtag in your text.
Bytes are not always the same as characters. Most keyboard characters are a single byte, but some are not. For example:
£ = 2 bytes € = 3 bytes.
You can check whether a character is single or multi-byte here.
Feature Types
The “type” defines whether the feature is a link or a tag. If a link, then the URI (URL) is defined. If a tag then the name of the tag is required and note that this does not include #.
Adding Multiple Features
Simply include more objects to the facets array to add additional links or hashtags.
Dynamic Content
To automate posts using dynamic content, hook the JSON payload together with your data source. When doing this, remember that you’ll need to calculate the position in bytes of the content to which you want to add a link or hashtag. Bear the following in mind:
The Len() function in Power FX and the OData length() function return character counts, not byte counts.
Stick to basic keyboard characters if you want to avoid misaligned byte offsets.
Summary
With facets, you can enrich your Bluesky posts by embedding links and hashtags seamlessly. Once you’ve mastered the basics, automating dynamic content becomes straightforward. Dive in and start experimenting. Your Bluesky posts are about to get a lot more engaging!