When I'm blogging I like to ensure that the content, as it is published, is sent out to my audience beyond just my normal RSS subscribers and I find that Twitter is an effective way to do this.
In the middle of 2017 I decided to rebuild my blog as a static site because I like writing in Markdown and I wanted a way that I felt more in control of the content. And last year I decided that I would make it a proper static website using Azure Storage Static Sites and use Azure Pipelines to automate the deployment.
Because this process can take a minute or two to run and then a few more minutes for the CDN to be purged and the new content deployed, I often would forget to tweet my new post, or I'd be furiously refreshing my home page, cursing the CDN for not purging fast enough!
So I decided it was time to take another approach, it was time to automate this little task out of my life.
Now, I could write a bit of code and deploy it as an Azure Function, run it on a timer to check my RSS and then write some more code to do the tweet, but I really wanted something as simple as possible.
This lead me to look at Logic Apps, which are similar to functions but is a codeless solution.
Quick overview of Logic Apps
Logic Apps are an integration tool, allowing you to create a workflow that is triggered by an event in an external system.
There are dozens of triggers available:
You can connect to a system like SalesForce, listen for a new record to be created and then start a new workflow. This workflow can perform a bunch of tasks, from manipulating the data in the trigger to calling another external system:
And all of this can be done without writing a single line of code!
Listening to blog publishes
While it might be interesting to explore SalesForce to SAP integration without writing any code we're actually looking at our blog. For this I'm going to select the When a feed item is published RSS trigger:
And provide it with the URL for my RSS feed:
I'm leaving the default polling interval, while I'm not publishing every 3 minutes, it does mean that when I do publish it will be picked up pretty quickly.
Tweeting our post
Logic Apps is listening now to when new articles are published, it's time to do something with them.
Since an item in the feed could have multiple URLs associated to it we want to iterate over them. Thankfully there's an Action in Logic Apps for that called For each
. We have to give it something to loop over, so we'll provide the Feed links
content from the trigger, selected from the Dynamic content panel that appears:
Finally, we can provide the Action to run for each link, we'll use the Post a tweet Action (you'll need to authorise Logic Apps to access the Twitter account you plan to use) and put in some information:
The Feed title
is the title of the article and Current item
is the link from the loop.
And you're done, publish an article and it'll automatically tweet a tweet per link that was associated with the new article (which, in reality, will likely be one tweet)!
Improving our tweet
While we're creating a tweet to ensure that we get the broadest reach we probably want to put a hashtag or two in place, and a logical way to do this is to grab the tags that you've put on the post, after all, they are the keywords you'd expect people to look for. When the new item came from the Trigger the tags are an array of strings (eg: [azureapril, azure, serverless, logicapps]
), but we want to convert that into a set of hashtags that we can append to the tweet.
To do this we'll use the Join
Data Operation Action, which takes a collection, and performs a string join operation using the join tokens you provide. We'll add that before our loop so we can then use the dynamic content in our tweet:
The joiner that I'm using is #
, so a leading followed by the
#
, so that we would end up with a string like azureapril #azure #serverless #logicapps
. Then in the tweet we'll put a #
before the dynamic content so the first tag also becomes a hashtag. 😉
Scheduling a follow-up tweet
When a tweet goes out it's a point in time, a message that will be seen by the people who are looking at their feed then. But I want to try and hit both the audience who is online right now and a future audience.
To do this we can add another Action to our Logic App, Delay. Delay allows us to, well, delay the following steps of the Logic App by a pre-determined time period. Let's delay by 12 hours to hit the people who were most likely asleep when the initial one went out, and then run a new loop:
Because it's a new tweet we can adjust the message a little (I add 'ICYMI', short for 'In case you missed it').
Conclusion
And there we have it, with a few clicks in the Logic App designer we can create a Logic App that will automatically tweet, and schedule a future tweet, each time we publish an article to our blog.
Also, with a Logic App you can export it as JSON, I've done that if you want to get started quickly (just remember to update the RSS link and Twitter connection):
Top comments (0)