Send community news by email using Power Automate

Yesterday on Reddit I was asked about how to collect and send community news articles from websites using Power Automate so that news letters can be sent out to colleagues.

Of course my initial response was to get some AI to do the trick. And Power Automate has that useful Run a prompt action for this.

The actual solution

The actual solution was a bit more complicated than this.

When you ask the Run a Prompt action to do anything it quite quickly tell you to do it yourself.

Collecting interesting community news sites

In my example, I will get the Run a Prompt action to generate me a list of site URLs. If you have a set number of sites that you want to have a look at then you can of course always create the list of URLs yourself. But I’m going to get the AI tools in Power Automate to do the job for me.

Using Run a Prompt to get a list of community news sites
Using Run a Prompt to get a list of community news sites

As we run this flow we will straight away see the first bit of trouble.

The URLs of community news sites returned by the run a prompt action
The URLs of community news sites returned by the run a prompt action

The output that we get is user-friendly and not flow-friendly.

Here are three popular Power Automate blogs excluding Microsoft blogs, presented in the requested JSON format:

[
{ “site”: “SharePains”, “URL”: “https://sharepains.com/” },
{ “site”: “Flow Joe”, “URL”: “https://flowjoe.io” },
{ “site”: “April Dunnam”, “URL”: “https://www.sharepointsiren.com” }
]

If you need more recommendations or specific topics covered in these blogs, please let me know.

With a bit of expression work we can sort out the out put quite quickly. But it would really be useful if prompts could just return the data in json without the fluff.

@{json(concat('[',split(
   split(
      outputs('Run_a_prompt_1')?['body/responsev2/predictionOutput/text']
      , '['
    )[1]
  , ']'
)[0],']'))}

Now that we have the json output as shown below we can start collecting our posts from each blog.

[
  {
    "site": "SharePains",
    "URL": "https://sharepains.com/"
  },
  {
    "site": "Flow Joe",
    "URL": "https://flowjoe.io"
  },
  {
    "site": "April Dunnam",
    "URL": "https://www.sharepointsiren.com"
  }
]

Getting the post content

You might think that you can simply ask for the latest post content. But unfortunately that doesn’t work. Even guiding the Run a Prompt action to my RSS feed didn’t help.

Attempt to collect posts using Run a Prompt action
Attempt to collect posts using Run a Prompt action

Using the RSS feed

The List all RSS feed items action will be helpful here. Of course it does mean that the sites will need to have the RSS feed enabled.

RSS feed is the easier way to collect posts
RSS feed is the easier way to collect posts

To limit the posts returned for the last 7 days I’m using the following expression

addDays( UTCNow(), -7,'yyyy-MM-dd')

Processing the RSS feed

Now the obvious way forward would be to add an apply to each into the earlier apply to each. However that isn’t very helpful as you will end up with a flow that is difficult to debug. Hence it is better to implement the below section in a child flow.

Scrape the posts
Scrape the posts and summarize the content

Please not that the flow will summarize the content. Please do not take full content of posts as that could get you into trouble with copyrights! And bloggers like to get visitors to their blog as well.

So in addition to the above you could also include a link to the source posts. Simply add the link that you have looked at in the HTML to text action’s Content property.

Reorganising the flow

Nested flows are hardly ever a good idea. So I’m converting my main news flow to look like this.

Reorganise our parent flow to generate the community news content
Reorganise our parent flow to generate the community news content

The Compose at the end takes the output from our Run a Child flow action as we have seen so often in my previous posts.

And our Child flow will now do the processing of the posts.

Flow to process a blog site
Flow to process a blog site

And again we’re collecting an array of data from our actions inside the apply to each.

Now that our flows are ready, we should consider adding error handling into these flows. The RSS feed might not always be the most reliable service, hence you might want to handle any failures. A simple try catch in both flows can sort that out.

Sending the email

Now the final step is to send out the email to your audience.

Flow diagram illustrating a sequence of steps in an automated email process, including recurrence, prompt handling, composing messages, and sending an email to a recipient.
Send community news by email using Power Automate 1

We just take the output of the Compose action that collects the data from the child flows and the content of the newsletter is ready.

You can of course add some more formatting to the Body to dress up the email a bit.


Discover more from SharePains

Subscribe to get the latest posts sent to your email.

Related Posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.