Loading...

Power Automate - How-to Posting on BlueSky and Mastodon

Power Automate - How-to Posting on BlueSky and Mastodon
Featured image of post Power Automate - How-to Posting on BlueSky and Mastodon

Introduction

Do you want to save time and effort by automating your social media posts across different platforms? Do you want to learn how to use Microsoft Power Automate to post on BlueSky and Mastodon with ease? If so, this guide is for you.

Integrating Mastodon with Hugo Blog for Comment Management

To streamline the management of comments on my Hugo blog, I have implemented a Mastodon workflow. This workflow allows for easy retrieval of Mastodon post IDs. I use Mastadon as my comments platform as described in Carl Schwan’s blog post.

Creating the Flows:

I will provide you a detailed breakdown suitable for a custom implementation. This guide will ensure even those not deeply familiar with technical details can follow along.


Detailed guide for creating a Custom BlueSky Posting Workflow in Microsoft Power Automate

Introduction

This section focuses on setting up a custom workflow in Microsoft Power Automate for posting updates to BlueSky, a social media platform. The workflow involves creating a session, posting content, and handling responses. At the time of writing, BlueSky is still invite-only, so you’ll need to request access to the platform before you can use this workflow. If you need access plesae contact me via Twitter, LinkedIn or in the comments down below.

Prerequisites

  • Access to Microsoft Power Automate.
  • BlueSky account credentials and API access.

Tips:

  • Ensure you correctly handle the authentication and authorization part, particularly the management of JWT tokens.
  • Test each part separately to ensure they work as expected.
  • Be mindful of the data structure expected by BlueSky’s API when creating posts.

This should give you a good starting point for rebuilding the BlueSky posting workflow in Power Automate. Adjust the steps according to your specific requirements and the exact response structure of the BlueSky API.

Create a New Flow in Power Automate

  1. Log in to Microsoft Power Automate.
  2. Navigate to My flows.
  3. Click on New flow and select Instant cloud flow.
  4. Name your flow, e.g., “Send to BlueSky”, and select the Manually trigger a flow trigger. Click Create.

Steps and Expressions (BlueSky)):

  1. Trigger: Manual trigger with text, link, and heading inputs.

  2. Initialize Variable - Complete Text:

    Merge the ShortText and link inputs into a single string. - Expression: @{triggerBody()?['text']} @{triggerBody()?['text_1']}

  3. Initialize Variable - Remove Line Breaks:

    - Expression: @{UriComponentToString(replace(uriComponent(triggerBody()?['text']) '%0A' ''))}

  4. Initialize Variable - Facets: As an array variable.

  5. Compose - Get Single Words:

    • Expression: @split(variables('Text'),' ')
  6. Apply to Each: Based on ‘Compose - Get Single Words’ output.

  7. Condition: Checks for hashtag (#) in each item.

    • Expression: startsWith(@items('Apply_to_each'),'#')
  8. Append to Array Variable - Hashtags:

    • Expression for tag: { "index": { "byteStart": @{indexOf(triggerBody()['text'], item())}, "byteEnd": @{add(indexOf(triggerBody()['text'],item()),length(item()))} }, "features": [ { "$type": "app.bsky.richtext.facet#tag", "tag": @{item()} } ] }
  9. Append to Array Variable - Mentions:

    • Expression for Links:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
    "index": {
        "byteStart": @{indexOf(variables('Complete Text'), item())},
        "byteEnd": @{add(indexOf(variables('Complete Text'),item()),length(item()))}
    },
    "features": [
        {
        "$type": "app.bsky.richtext.facet#mention",
        "handle": "@{item()}"
        }
    ]
}
{
    "index": {
        "byteStart": @{indexOf(variables('Complete Text'), triggerBody()['text_1'])},
        "byteEnd": @{add(indexOf(variables('Complete Text'),triggerBody()['text_1']),length(triggerBody()['text_1']))}
    },
    "features": [
        {
        "$type": "app.bsky.richtext.facet#link",
        "uri": "@{triggerBody()['text_1']}"
        }
    ]
}

Explanation: The expression uses the Complete Text variable to find the position of the link in the text using the indexOf function. It then creates the link facet using the link input from the trigger. For more information on the BlueSky API, refer to the documentation.

  1. HTTP - Create Session:

    • URI: https://bsky.social/xrpc/com.atproto.server.createSession
    • Body: { "identifier": "@{parameters('BlueSky_UserName')}", "password": "@{parameters('BlueSky_App-Password')}" }
  2. Parse JSON - New Session Response: Tipp: Use the Generate from sample option to generate the schema. To get the sample, you can use the Run Flow option and copy the response from the Run History.

  3. HTTP - Post Post:

    • URI: https://bsky.social/xrpc/com.atproto.repo.createRecord
    • Body: { "repo": "@{parameters('BlueSky_HandleName')}", "collection": "app.bsky.feed.post", "record": { "createdAt": "@utcNow()", "facets": "@if(equals(length(variables('facets')),0),'[]',variables('facets'))", "text": "@variables('Complete Text')" } }
    • Authentication: Requires an API key from BlueSky Social’s account settings​​.

Send2Mastodon

Here’s the step-by-step tutorial:

Prerequisites

  • Access to Microsoft Power Automate.
  • Microsoft Teams set up.
  • Mastodon account and API key.

Create a New Flow in Power Automate

  1. Log in to Microsoft Power Automate.
  2. Navigate to My flows.
  3. Click on New flow and select Instant cloud flow.
  4. Name your flow, e.g., “Send to Mastodon”, and select the Manually trigger a flow trigger. Click Create.

Steps and Expressions

To recreate the workflow in Power Automate based on the provided JSON file, follow these steps:

  1. Trigger: Manual trigger with text, link, and heading inputs.

  2. HTTP Request to Mastodon API:

    • Add an HTTP action to post a status update to Mastodon.
    • Set the method to POST.
    • Set the URI to https://[Mastodon Server Link]/api/v1/statuses replace [Mastodon Server Link] with the actual server link.
      I used environment variables for this as I store everything in a solution.
    • Add headers:
      • Authorization: Bearer [Mastodon-Key] (replace [Mastodon-Key] with the actual key).
      • Content-Type: application/x-www-form-urlencoded.
    • Set the body to send the status and link: "status=@{triggerBody()?['text']}\n@{triggerBody()?['text_1']}".
  3. Parse JSON:

    • After the HTTP request, add a “Parse JSON” action.
    • Use @body('HTTP') as the content.
    • Define the schema based on the expected response from the Mastodon API. Tipp: Use the Generate from sample option to generate the schema. To get the sample, you can use the Run Flow option and copy the response from the Run History.
  4. Post Message in Teams Channel:

    • Add an action to post a message in a Teams chat or channel.
    • Configure the message to include the Mastodon toot ID and the heading from the trigger inputs.
    • Use the expression @{triggerBody()?['text_2']} for the heading and @{body('Parse_JSON')?['id']} for the Mastodon toot ID.
  5. Final Steps:

    • Save and test the flow to ensure it works as expected.
    • Make any necessary adjustments to the expressions and configurations based on your specific requirements and the structure of your Mastodon instance and Teams setup.

Conclusion

This guide provides an overview of using Microsoft Power Automate to automate social media posts across various platforms, like BlueSky, Mastodon and LinkedIn. I hope you found this guide useful and that it helps you to get started with Power Automate. If you have any questions or feedback, please leave a comment below. Also you can combine this with a SharePoint list to create a queue for your posts. If this is interessting for you I will cover this in a future post. I added the Flows to my GitHub repo so you can download them and import them into your environment.

References

Published on:

Learn more
Need help with this product?

We can help you with Power Automate - How-to Posting on BlueSky and Mastodon

If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.

The State of the Microsoft 365 Nation
The State of the Microsoft 365 Nation

Recent content on The State of the Microsoft 365 Nation

Share post:

Related posts

Creating Copilot Studio Agents Without an M365 Copilot Premium License

A common assumption when getting started with Copilot Studio is that you need a full Microsoft 365 Copilot Premium license. That assumption is...

6 months ago

Power Automate: Get events (V4) shared mailbox fix

When your flow reads a shared mailbox calendar using the Office 365 Outlook → Get events (V4) connector, it can fail in a way that looks like...

8 months ago

Using Managed Identity with Azure Automation & PnP.PowerShell

How to Set Up a Managed Identity for Azure Automation Runbooks and Use It in PowerShell Scripts with PnP.PowerShell This guide walks you throu...

1 year ago

UPDATED - Set Up Pay-as-you-go M365 Chat & SharePoint Agents

Introduction to Pay-as-You-Go Agents in Microsoft 365 Microsoft has introduced a flexible way for organizations to leverage AI capabilities wi...

1 year ago

How to Use Flexible Sections in SharePoint Pages and News

If you’ve been using SharePoint Online to build pages or share news, you know how important it is to have a layout that works for your c...

1 year ago

What's New in SharePoint Pages

1. New Carousel Layout in the Hero Web Part The Hero Web Part has always been a fundamental element of SharePoint pages. The new Carousel Layo...

1 year ago

Power Platform Solutions Made Simple

Introduction to Power Platform Solutions Power Platform Solutions offer many benefits, especially when moving from standalone flows and apps t...

1 year ago

Use your Bluesky post for comments on your Hugo Blog

Since Bluesky is getting really popular by people I interact with, I decided to switch my blog comments to Bluesky posts. In this blog post, I...

1 year ago

Exploring SharePoint Online's SiteAssets Library

The SiteAssets library in SharePoint Online often seems like a mystery to a lot of users I talk to, but it’s important to understand it ...

1 year ago

Step-by-Step Guide to Copy Pages between SharePoint Online

Unfortunately you can’t copy pages in SharePoint through the UI. But sometimes you may need to copy pages and their associated SiteAsset...

1 year ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.