Power Automate (Flow) to share communications into multiple Microsoft Teams at once

In my other blog post, I walked through the business case and options behind this flow. My goal in this post is to dive deeper into what the flow is and how it was built.

Beauty, isn’t it?

For starters, the flow is an Automated flow using a SharePoint – When an item is created trigger. I attached it to the Communications list. (see my other blog post for more details on what this and other lists entail)

Then I grab all of the Teams’ webhook addresses from the list Comms Teams using a SharePoint – Get items action.

I create a new variable called learnMoreAction, using Variable – Initialize Variable action. I configure it as an object and set the value to nothing, emtpy, nada.

Then I check if a Link to Content was provided in the communication. If it was, then we’ll create a button for our Teams card for the user to learn more. If not, we don’t want a button. My condition is set to Link to content is equal to (blank).

If it is blank, we do nothing. If it’s not blank, we update the variable learnMoreAction to contain the necessary JSON to show a button.

The JSON code is:

{
  "@@type": "OpenUri",
  "name": [ Link Name ]
  "targets": [
    {
      "os": "default",
      "uri": [ Link to Content ]
    }
  ]
}

IMPORTANT note the @type in the screen shot but in my code above I have @@type. There is something annoying with Power Automate. It requires @@ but when you save it and come back, it reverts to one @ so then you have to add it back in again. Really weird.

Next, we loop through the Teams and post the content. The Apply to each action will add itself when you perform the next step.

To post to the Team’s webhook, we use an HTTP action.

Configure the HTTP action:

  • Method, POST
  • URI, use the Webhook field from the SharePoint list Comms Teams. When you add this field, then the Apply to each action gets added automatically.
  • Headers, specify Content Type with application/json
  • Body, the rest of the JSON is required, and is available below
{
  "@type": "MessageCard",
  "@context": "https://schema.org/extensions",
  "summary": [ Communications - Title ],
  "themeColor": "0078D7",
  "title": [ Communications - Title ],
  "sections": [
    {
      "text": [ Communications - Subtitle ]
    }
  ],
  "potentialAction": [
    [ Variable - learnMoreAction ]
  ]
}

You can learn more about what options exist for your card in Teams on Microsoft’s site. You could also add interactive action buttons to receive feedback from your users on the communications!

After the HTTP action, we have 2 actions, one runs if it was successful, the other runs if it failed.

The successful action uses SharePoint – Update item action. It simply updates the item from Comms Teams list item it just posted to with the current date and time.

Set Last Published field to utcNow() expression.

The failed action also uses SharePoint – Update item action. To add this, first select Add a parallel branch instead of adding a new action, then select the action.

This action has been configured to run after only when Failed or Timed Out. To configure this, click the menu for the action, then Configure run after.

When this action runs, it updates the Comms Teams list item it just attempted to post to with a date in the Last Error field, and comments so I can chase down which comms didn’t work.

Alternatively, I could add an email action after this as well to email me when it fails.

That’s it!

Pretty straight forward. Let me know in the comments if you have any comments or questions. What would you do differently?

One thought on “Power Automate (Flow) to share communications into multiple Microsoft Teams at once

Add yours

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Create a free website or blog at WordPress.com.

Up ↑

%d bloggers like this: