Categories: Tools and Tips
*** NOTE: ALL INFORMATION IS ACCURATE AT DATE OF PUBLISHING ***

You are probably thinking, this post is different to your normal stuff Megan V. Walker. Well yes, yes it is! I have started to embrace Mastodon and moving more and more away from interacting on Twitter for MANY reasons (not something to go in to in this post), and actually finding I am really enjoying interactions on Mastodon. One thing that had bugged me though, I had no way to automate new posts to go out on to the social site without using a tool that pushed FROM Twitter through in to Mastodon. I use Buffer to post from a plugin in WordPress, which then goes out to Facebook, Twitter and LinkedIn. Although they are considering creating the option for sharing to Mastodon, it likely will be a while (check out their awesome post if you want to understand more about what Mastodon is). I figured I would just have to wait, until an awesome exchange on Mastodon lead me down a path I had never taken before.

Power Automate Custom Connector

I happened to see a post from Jeremy Sinclair, a fellow Microsoft MVP but in the Windows Development award category. He had written a blog about creating a Power Automate custom connector for Mastodon. Awesome! This was EXACTLY what I needed… but I had never build one before. I should not have worried as his blog, which you can find here, is very thorough. Even when I ran in to issues and was banging my head against a wall, he responded to my questions on Mastodon and helped me get to a successful post going out from my new connector in Power Automate. Such a sense of satisfaction!

Custom RSS Feed

Now that I had my connector, I just needed to create a quick simple flow using the standard RSS Feed Connector for Power Automate. Simple! Ugh, well not really THAT simple. I have already customised my RSS feed slightly and use it to generate my emails that go out to subscribers letting them know I have posted some new content. The excerpt of the blog post is a specific link, and then I have a ‘Continue Reading’ link at the end that is a hyper link to the post. First, that length was TOO long for Mastodon. You can have up to 500 characters, but along the excerpt I wanted to show the blog post title, and the link itself, and some hashtags.

So, I needed to add in a new feed just for this purpose. I use WordPress, and knew I could create a custom RSS feed but needed a refresher. There are lots of posts out there, but I used this, were the feed details need to be added to your functions.php file. DO NOT EDIT THIS unless you are comfortable and familiar with editing or creating WordPress themes. This is everything I added to the bottom of my file. You can see that I added a feed called Mastodon which then forms part of the URL for the path to the RSS feed. I also set a trim for the excerpt so I could control the number of words that would be included from the start of my post (or the excerpt) and also made sure the category of the blog post was included too.

function init_rss_feed_custom( ) {
    add_feed('mastodon', 'add_rss_feed_custom');
}
add_action('init', 'init_rss_feed_custom');

function add_rss_feed_custom ( ) {
  header('Content-Type: application/rss+xml');
  ?>
<rss version="2.0"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:atom="http://www.w3.org/2005/Atom"
        xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
        <?php do_action('rss2_ns'); ?>>
<channel>
        <title><?php bloginfo_rss('name'); ?> - Feed</title>
        <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
        <link><?php bloginfo_rss('url') ?></link>
        <description><?php bloginfo_rss('description') ?></description>
        <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
        <language><?php echo get_option('rss_language'); ?></language>
        <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
        <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
        <?php do_action('rss2_head'); ?>
        <?php while(have_posts()) : the_post(); ?>
                <item>
                        <title><?php the_title_rss(); ?></title>
                        <link><?php the_permalink_rss(); ?></link>
                        <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
			<updated><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false ); ?></updated>
                        <dc:creator><?php the_author(); ?></dc:creator>
                        <guid isPermaLink="false"><?php the_guid(); ?></guid>
			<category><?php $category = get_the_category(); echo $category[0]->cat_name; ?></category>
                        <description><![CDATA[<?php echo wp_trim_words( get_the_excerpt(), 45, '...' ); ?>]]></description>
                        <content:encoded><![CDATA[<?php echo wp_trim_words( get_the_excerpt(), 45, '...' ); ?>]]></content:encoded>
	                 <?php rss_enclosure(); ?>
                        <?php do_action('rss2_item'); ?>
                </item>
        <?php endwhile; ?>
</channel>
</rss>
  <?php

}

Flow In Power Automate

Now that I had my custom RSS Feed, and my awesome Mastodon Custom Connector, I could put the two together. The flow is pretty simple. I just use the RSS Feed connector for the trigger which will run whenever I have a new blog post that is published. This will then hit my new feed and off we go!

Click to view in detail

One of the things that Mastodon uses A LOT for finding the right content, is hashtags. I wanted to take the category from my blog post, extract everything that comes through in the categories array, remove any spaces between words, and then add a hashtag in front of it. Then we get a series of hashtags if you use more than one category. Special thanks to Linn Zaw Win for helping me take the three compose steps I had and making it one. Much more efficient!

@{concat('#',replace(join(triggerOutputs()?['body/categories'],', '),' ',''))}
Click to view in detail

Then you can add in the step from your custom connector to post a status. You can obviously put whatever you like. I have the title of the feed, then the summary (which is my truncated excerpt of 45 words), then the primary feed link which is the link back to the blog post, and then the Output from the Compose step. I also then have a couple of other expressions to add in some additional hashtags depending on if Dynamics is included in part of the category name. You can do something like this:

if(contains(outputs('Convert_Categories'), 'Dynamics'), '#Dynamics365 #PowerPlatform #BusinessApplications', '')
Click to view in detail

That’s it! Pretty simple, and gets my content out to Mastodon automatically from my website. Hooray! Oh and if you decide to join, you can find me here: Megan V. Walker on Mastodon.


Check out the latest post:
Split Your Audience By Number Or Percentage In Customer Insights - Journeys


This is just 1 of 480 articles. You can browse through all of them by going to the main blog page, or navigate through different categories to find more content you are interested in. You can also subscribe and get new blog posts emailed to you directly.




Leave a Reply

Your email address will not be published. Required fields are marked *