Weekly digest for twitter with Logic Apps
To keep your readers up to date and to deliver constant social media activity, it’s a great idea to provide weekly digests to your readers. And what could be better to get the job done than Azure Logic Apps ;)
Table of Contents
- Logic App
The things we need are
- Available rss feed of the current blog posts
- An Azure Account
- A Twitter account
For our blog we chose the following layout for the twitter posts:
ItInsights Weekly Digest CW XX
We start with an empty Logic App.
To collect all the information needed, we will
- Get all post from the rss feed
- Filter for the defined interval (7 days)
- Concat everything together
- Post it on twitter
In the following steps we will build up the needed actions step by step.
As a trigger we use the Recurrence Action from Logic Apps with the following configuration:
To collect all posts into a variable, we need to initialize it first. To declare a variable, we use the “Initialize variable” action.
To get a recent list of blog posts, we create a “List all RSS feed items” action. The only important parameter is the RSS feed URL. At our blog, the rss feed is located at
To collect posts, we first create a “For each” to loop with a Condition over all posts to determine the ones that were released in the last week (7 days). As condition we use and expression to convert the field
publishDate to DataTime. Then we check if it is greater than the current date decreased by 7 days.
We use the automatic “Body” variable from the previous “List_all_RSS_feed_items” step.
We don’t handle the false case, but add an additional “For each” to the true case.
This will be used to append all post links to the “posts_string” variable with the “concat” function.
Thanks to the nested property “Feed links”, we can directly use that variable and don’t need to add logic to get the post links.
We need to add a line break with
\n. This will not be displayed correctly in the Logic Apps Designer and has to be added in the code view.
The last step is to post the collected post links with our defined body on Twitter.
We will use the “Post a tweet” action from the Twitter connector. To use twitter, you have to add a connection after adding the action. Click “Add new” and fill in your Twitter credentials in the following pop-up window. The Oauth token will securely be stored in the background and Azure automatically acquires a new access token every time an action with the specified connection will be used.
The interesting part is the expression to generate the tweet text:
concat('ItInsights Weekly Digest CW ', If(greater(div(float(dayOfYear(utcNow())),7),div(dayOfYear(utcNow()),7)),div(add(dayOfYear(utcNow()),6),7),div(dayOfYear(utcNow()),7)), '\n\n',variables('posts_string'), '\n', '#weekly #digest #insights')`
We use an expression from the powerusers community to get the current calendar week. The algorithm could be known from common coding languages, but a user from the flow community managed to get it to run with the limited functions available in expressions. We just changed it a little bit and changed the third 7 to a 6 to work for the current week.
Here is the link to the discussion: How-to-calculate-week-number-in-a-year-in-flows
We need to add a line breaks with
\n. They will not be displayed correctly in the Logic Apps Designer and have to be added in the code view.
Thats it for today, have fun and be creative using the twitter connector from Logic Apps :)