SOLUTIONS FOR MICROSOFT POWER PLATFORM

Fight Notification Overload in Microsoft Teams — Manage Tags with Power Automate and Microsoft Lists

One of the downsides of modern collaboration and its tools is notification overload. We can fight notification overload through Tags in Microsoft Teams managed with Microsoft Graph, Microsoft Lists, and Power Automate.

Sebastian Zolg 🤝
9 min readAug 16, 2021

--

Photo by Prateek Katyal on Unsplash

People tend to mention everyone by using @Channel or @Team, causing great distraction and a loss of focus. As a result, people start to turn off notifications completely.

Tags can solve this problem. For example, we can use tags to create groups of people in a specific role or function, such as the IT Team or the UX Design Team, and @mention only the tag. Then, only people subscribed to the tag will get a notification. This allows us to target the audience very specifically and helps fighting notification overload.

Tags can be created and managed right inside Microsoft Teams. However, they are hard to keep in sync since the logical grouping of people usually happens outside of Microsoft Teams and changes constantly.

Here are some sources of logical groups and their systems:

  • HR Systems, e.g. everyone who is in the Role of a Product Manager
  • SaaS Services, e.g. everyone with an Adobe Cloud subscription
  • CRM Systems, e.g. different Sales Teams in Salesforce or Dynamics 365
  • IT Systems, e.g, Azure Active Directory Groups

Wouldn't it be wonderful to create tags automatically and assign people based on these outside systems? Luckily, we can do this with the help of Power Automate and Microsoft Graph.

The Scenario

To simulate such an outside system, we take a straightforward approach using Microsoft Lists. The resulting workflow can be adjusted to your own systems, or you stick with the Microsoft List as an intermediate, meaning you write to the Microsft List from the outside system using a separate workflow in Power Automate or any other tooling.

High-level steps:

  • Create an Application Registration
  • Create a Microsoft List
  • Create a Power Automate Flow to sync Tags to Teams

Since this article is written for citizen developers, creating an Application Registration in Azure Active Directory can be difficult, and you might need the help of your IT department. That is why I’ve put the necessary steps at the very end of this article to focus on the workflow first.

Create a Microsoft List

In any Team in any Channel, click the + icon in the tabs section, select Lists from the app catalog, and click save to add the list to the Team.

Click the Create a list card and select Blank list from templates.

Give the list a name and click Create.

The newly created list already contains a Title column which we will use as the name field for any new tag. What we need is a second column containing the people assigned to that tag. Every tag needs at least one person assigned to it by design.

Click +Add column and select Person.

Give the column a name such as Members and toggle Allow multiple selections and Require that this column contains information on.
Finally, click the Save button, and our list is ready.

In Power Automate, select Automated cloud flow, give it a name such as Sync Tags to Teams, select the When an item is created or modified trigger, and click Create.

Select your Team/Sharepoint Site and the List from the drop-down fields so that this flow fires when a new item is added.

Next up, we need three variables. A Members variable (Array) to hold all people added to the tag, a MemberIds variable (Array) to store the fetched unique id of every person, and a ClientSecret (String) to wire the flow with the Application Registration (see the ‘Explained’ section at the end).

Click +New step and add the Initialize variable action for every variable.

We set the Members property of our trigger body as value for the Members variable (see Screenshots), which corresponds to the Members column in our list.

MemberIds’ value can be left blank.

For the ClientSecret, we put the secret of our Application Registration (see the ‘Explained’ section at the end).

Since tags are scoped to a team, and we want to specify which team we create the tags with, we add the Get Team action and select the destination team from the drop-down list.

Next, we add an Apply to each action (a.k.a loop) and set the Members variable as the input.

Inside the loop, click the Add an action link and select Get user profile (V2) from the list of actions.

We need the user's email address from the current iteration for the User (UPN) field. For this, we use the item()['Email'] expression.

As a result of that action, we get the user's full profile, including the unique id. We store the id of every user inside the previously created MemberIds variable by appending it to the array.

Copy and paste the following code snippet into the Value field of the append action.

{
"userId": "@{outputs('Get_user_profile_(V2)')?['body/id']}"
}

Now that we have an array of all users and their unique Ids, we can compose an object that we can send to the Microsoft Graph to create a new tag and assign the people.

Outside the loop, add a Compose action and set the MemberIds variable as input.

We can now invoke the Microsoft Graph API to create a tag and assign the people to it. To communicate with the Microsoft Graph API, we add an HTTP action below the compose action.

Configure the HTTP action as follows:

Method: Post
URI:

https://graph.microsoft.com/beta/teams/@{outputs('Get_a_team')?['body/id']}/tags

Body:

{
"displayName": "@{triggerOutputs()?['body/Title']}",
"members": @{outputs('Compose')}
}

Authentication: Active Directory OAuth
Audience: https://graph.microsoft.com
Tenant: Your Tenant Id
Client ID: Your Client Id
Secret: ClientSecret Variable

If by chance your secret contains special characters, encode it with the encodeUriComponent(variables('ClientSecret')) expression.

As a final but optional step, we post a message to Microsoft Teams once a tag was created. Along with the message, we post the Id of the newly created tag. With this Id, you can create automated flows which @mention the tag in a Teams message. I’ve written a whole article about it.

To do this, add a Post message in chat or channel action to your flow and select the Team and Channel you want to post the message to. To access the Id of the tag, use the following expression body('HTTP')['Id'].

Our flow is ready, and we can test it. Click the Test button in the top right corner, select Manually and click Test. Now the flow waits for the trigger to fire.

Hop over to your list in Teams, click Edit in grid view and create any tag you want. In the Members column, add the people you want to assign to the tag initially. When ready, click Exit grid view to save your changes.

If everything went well, a message is posted to the given channel, telling you and the team that a tag was synced to Teams, including its tag Id.

If you came this far, then you did very well! You can now mention a specific group of people inside Microsoft Teams. Teams will only notify the people assigned to this tag.

From this point on, you can tweak your flow to connect to any other system than a Microsoft List or implement support for updating tags and members (see the ‘Bonus’ section below).

I hope it helps.

👉,
— Sebastian

Explained: Create an Application Registration

Application Registration is necessary, so your flow gets permission to create tags on-behalf of its own (a.k.a, application permission). Out of this process, you get the ClientId , TenantId and ClientSecret which are required to implement the above scenario.

Go to the Azure Portal and click +New registration.

Give the app a name and leave the defaults. Click Register.

Once registered, copy the client Id and the tenant Id to use them in the flow.

Under Certificates & secrets, click +New client secret, give it any name + suitable expiration date, and copy the Value. This is your ClientSecret.

Under API permission, click +Add a permission.

Select Microsoft Graph from the list of Microsoft APIs.

Select Application permission and choose TeamworkTag.ReadWrite.All from the list of permissions. Click Add permission when ready.

To grant org-wide permission, click the Grant admin consent button, and you’re done.

Now you have everything you need to implement the above flow.

Bonus: Updating Tags

An obvious next step is implementing workflow logic that can handle updates to tags.

You already have all the building blocks you need. The only thing to know is how to update (a.k.a PATCH) a tag through the Microsoft Graph API. You can find all the calls in the official documentation.

Since we already have the Tag Id, you can construct a PATCH request like this:

Method: Patch
URI:

https://graph.microsoft.com/beta/teams/{{TeamId}}/tags/{{TagId}}#Replace {{TeamId}} with the Id of your Team.
#Replace {{TagId}} with the Id of the tag you want to update.

Body:

{
"displayName": "New Name"
}
# Use the "members" array property to set new members.

--

--

Sebastian Zolg 🤝

I’m an IT professional with experience in enterprise mobility, workplace, cloud technologies, and software development. sebastianzolg.de