Action
Post to Bluesky
UPDATES
1 day ago
Custom domain support (hopefully)
created by @FlohGro / more on my Blog
Post to Bluesky
Post the content of the current draft to your Bluesky account
[Configuration]
Before you can use this action you need to configure your username and an app password (and domain if you use a custom domain).
To configure your username edit the action and change the template value for [[username]]
from UNDEFINED
to your username on Bluesky (e.g. flohgro.bsky.social) without the @ sign.
To configure the app password you need to change the template value for [[app_password]]
from UNDEFINED
to a password you can create as follows:
- open your Bluesky settings (on web or the iOS app)
- select Privacy and security
- select App passwords
- Tap Add App Password
- choose a name for the password (e.g. Drafts)
- Tap Next
- Copy the displayed password
- Tap Done
- Insert the created password into the configuration of the action as described above
If you use a custom domain you need to configure your domain by changing the template value for [[domain]]
from bsky.social
to your domain. Please note: This is NOT required if you just changed your user handle to your own domain name. In this case you need to use that domain as username (e.g. flohgro.com) and keep the domain as it is.
[Usage]
After configuring it properly you can post the content of the current draft with this action. The action will not check for invalid length of the post so if something fails, you can check the action log for the error message (e.g. if your text was too long).
If you find this useful and want to support me you can donate or buy me a coffee
Steps
-
defineTemplateTag
name username
template UNDEFINED
-
defineTemplateTag
name app_password
template UNDEFINED
-
defineTemplateTag
name domain
template bsky.social
-
script
const username = draft.processTemplate("[[username]]").trim(); const appPassword = draft.processTemplate("[[app_password]]").trim(); const domain = draft.processTemplate("[[domain]]").trim(); const content = draft.content function checkConfig() { if (username == "UNDEFINED") { const message = "username not defined" app.displayErrorMessage(message) context.fail(message) return false } if (appPassword == "UNDEFINED") { const message = "app password not defined" app.displayErrorMessage(message) context.fail(message) return false } return true } function authenticateAndPost() { // Base URL for the Bluesky API const baseUrl = "https://" + domain + "/xrpc/"; // HTTP object for making requests const http = HTTP.create(); // Step 1: Get the Bearer token (Session Token) const authRequest = { // url: `${baseUrl}com.atproto.server.createSession`, url: `${baseUrl}com.atproto.server.createSession`, method: "POST", headers: { "Content-Type": "application/json", }, data: { identifier: username, password: appPassword, }, }; const authResponse = http.request(authRequest); if (authResponse.statusCode === 200) { const session = JSON.parse(authResponse.responseText); const bearerToken = session.accessJwt; // Step 2: Create a post using the Bearer token const postContent = { repo: username, collection: "app.bsky.feed.post", record: { text: content, createdAt: new Date().toISOString(), // Current timestamp }, }; const postRequest = { url: `${baseUrl}com.atproto.repo.createRecord`, method: "POST", headers: { "Content-Type": "application/json", Authorization: `Bearer ${bearerToken}`, }, data: postContent, }; const postResponse = http.request(postRequest); if (postResponse.statusCode === 200) { const data = JSON.parse(postResponse.responseText); console.log("Post created successfully:", data); return true } else { app.displayErrorMessage("posting failed"); const message = "Error: " + postResponse.statusCode + "\n\n" + postResponse.responseText; context.fail(message); return false } } else { app.displayErrorMessage("authentication failed") const message = "Error: " + authResponse.statusCode + "\n\n" + authResponse.responseText; context.fail(message); return false } } // actually run something - if config is fine, exectue authenticate and post if (checkConfig()) { authenticateAndPost() }
Options
-
After Success Default , Tags: bluesky, published Notification Error Log Level Info