Microsoft Flow: Converting Feed Categories to Hashtags

In a number of previous posts starting with this one, I’ve covered ways to use Microsoft Flow to post to to your Twitter and LinkedIn feeds when you publish a blog post. One thing I haven’t covered in those posts is doing something with your categories. This time, we’ll walk through adding steps to our flow to convert the categories from our blog post into hashtags for our Twitter and LinkedIn posts.

New Variable

The first thing we’re going to need is a new variable to store our array of categories. Go back to your flow that you created to post to Twitter and LinkedIn and add a new variable. For this example, we’ll call it “categories”. It will be of type array and we’ll set its initial value to the “Feed categories” output from our RSS feed trigger.

Initialize variable step

Apply to each

The next thing we need to do is add an “Apply to each” loop that will iterate through the categories and convert each one into a hashtag. We’re going to put that final list of hashtags into our description variable that we created previously. Given the limited space in posting anything to Twitter, we’re going to want our hashtags instead of our summary text to come in after the post’s title. So, find the “Set variable” step that was setting the value of our description variable to the “feed summary” output from our trigger and delete it.

Next, just after the new variable step above, add an “Apply to each” action. As our “output from previous steps”, select the categories variable we just created. Inside of the loop add two consecutive “Compose” actions and then a “Set variable” action.

In our first Compose action, we’re going to set the Inputs to the following expression:

concat('#', replace(item(), ' ', ''))

This will take the current item, remove any inline spaces and then add the hashtag symbol at the front. This will take a category such as “Microsoft Flow” and turn it into a typical social media hashtag of “#MicrosoftFlow”.

In our second Compose action, we’re going to set the Inputs to our description variable, followed by a space, and then ending with the Output from the first Compose action. This will add the current hashtag to previously added hashtags.

In our Set variable action, we’re going to set the value of Description to equal the Output from the second Compose action. Our full Apply to each loop should look like this:

An apply to each loop including two compose actions and a set variable action

Fin

That’s it! You’ve added hashtags to your social media posts. Now, picking the right categories for your posts? That’s up to you…

Leave a Reply