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

  1. Prerequisites
  2. Logic App
    1. Trigger
    2. Variable initialization
    3. RSS Feed items
    4. Collect Posts
    5. Concat and Post Tweet

Prerequisites

The things we need are

  1. Available rss feed of the current blog posts
  2. An Azure Account
  3. A Twitter account

For our blog we chose the following layout for the twitter posts:

1
ItInsights Weekly Digest CW XX
2
3
https://itinsights.org/article-name-01
4
https://itinsights.org/article-name-02
5
https://itinsights.org/article-name-03
6
7
#weekly #digest #insights

Logic App

We start with an empty Logic App.
To collect all the information needed, we will

  1. Get all post from the rss feed
  2. Filter for the defined interval (7 days)
  3. Concat everything together
  4. Post it on twitter

In the following steps we will build up the needed actions step by step.

Trigger

As a trigger we use the Recurrence Action from Logic Apps with the following configuration:

Recurrence TriggerRecurrence Trigger
1
"triggers": {
2
    "Recurrence": {
3
        "recurrence": {
4
            "frequency": "Week",
5
            "interval": 1,
6
            "startTime": "2019-02-22T09:00:00Z"
7
        },
8
        "type": "Recurrence"
9
    }
10
}

Variable initialization

To collect all posts into a variable, we need to initialize it first. To declare a variable, we use the “Initialize variable” action.

post_string initializationpost_string initialization
1
"Initialize_posts_string": {
2
    "inputs": {
3
        "variables": [
4
            {
5
                "name": "posts_string",
6
                "type": "String"
7
            }
8
        ]
9
    },
10
    "runAfter": {},
11
    "type": "InitializeVariable"
12
}

RSS Feed items

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 https://www.itinsights.org/atom.xml

Get RSS feed itemsGet RSS feed items
1
"List_all_RSS_feed_items": {
2
    "inputs": {
3
        "host": {
4
            "connection": {
5
                "name": "@parameters('$connections')['rss']['connectionId']"
6
            }
7
        },
8
        "method": "get",
9
        "path": "/ListFeedItems",
10
        "queries": {
11
            "feedUrl": "https://www.itinsights.org/atom.xml"
12
        }
13
    },
14
    "runAfter": {
15
        "Initialize_posts_string": [
16
            "Succeeded"
17
        ]
18
    },
19
    "type": "ApiConnection"
20
}

Collect Posts

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.

Outer For EachOuter For Each
1
"expression": {
2
    "and": [
3
        {
4
            "greater": [
5
                "@formatDateTime(items('For_each_2')?['publishDate'])",
6
                "@addDays(utcNow(), -7)"
7
            ]
8
        }
9
    ]
10
}

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.
concat(items('For_each'), '\n')
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.

Inner For EachInner For Each
1
"For_each": {
2
    "actions": {
3
        "Append_to_string_variable": {
4
            "inputs": {
5
                "name": "posts_string",
6
                "value": "@concat(items('For_each'), '\n')"
7
            },
8
            "runAfter": {},
9
            "type": "AppendToStringVariable"
10
        }
11
    },
12
    "foreach": "@items('For_each_2')?['links']",
13
    "runAfter": {},
14
    "type": "Foreach"
15
}

Notice:
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.

Concat and Post Tweet

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:

1
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

Post TweetPost Tweet
1
"Post_a_tweet": {
2
    "inputs": {
3
        "host": {
4
            "connection": {
5
                "name": "@parameters('$connections')['twitter']['connectionId']"
6
            }
7
        },
8
        "method": "post",
9
        "path": "/posttweet",
10
        "queries": {
11
            "tweetText": "@{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')}"
12
        }
13
    },
14
    "runAfter": {
15
        "For_each_2": [
16
            "Succeeded"
17
        ]
18
    },
19
    "type": "ApiConnection"
20
}

Notice:
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 :)