@Mention a Tag in Microsoft Teams with Power Automate

While Power Automate is a great tool for building fully automated workflows and integrating natively with Microsoft Teams, not every scenario is supported out of the box or can be solved with true no-code. Sometimes it needs a bit more tender, and so it’s the case when you want to @mention a Tag in Microsoft Teams with Power Automate.

What are Tags in Microsoft Teams? Tags in Microsoft Teams let users quickly and easily connect with a subset of people on a team. You can create and assign custom tags to categorize people based on attributes, such as role, project, skill, or location. — Source: docs.microsoft.com

If you want to mention a Channel instead of a Tag, check out my previous article.

Create a Cloud Flow to @mention a Tag

Go to Power Automate and create a new Cloud Flow or modify any of your existing flows.

As the first step, we need to initialize 4 variables and fill in the corresponding values.

  • teamsId — the Id of the Team which holds your tag
  • channelId — the Id of the Channel you’d like to issue a message in
  • tagId — the unique Id of the Tag you want to mention
  • tagName — the display name of your Tag as created in Teams

How do I get these IDs? Getting the IDs isn’t straight forward, so I’ve put the steps in its own section at the end of this article.

Once you have all your variables initialized and all of the IDs set, add the HTTP with Azure AD (Premium) actionto the end of your flow.

When prompted enter https://graph.microsoft.com for both URL fields and click Sign in.

Connection to the Microsoft Graph

Choose POST as the method and add Content-Type: application/json to the list of headers.

Enter the following URL for the request:

https://graph.microsoft.com/beta/teams/@{variables('teamsId')}/channels/@{variables('channelId')}/messages

I’ve prepared a sample request body from where you can start and adopt it as needed. Just copy and paste it from the gist below (click view raw first).https://medium.com/media/2f17a239cbff1d23aaba36a2eb72ca96

Once you’ve saved your flow and ran it, you should see a new message in Teams with an @mention of your Tag. All members subscribed to that Tag will be notified by Microsoft Teams.

How to get Team, Channel, and Tag IDs in Teams?

Right now, there is no easy way to get all of those IDs. So, in my opinion, the simplest way for an ambitious citizen developer is to look behind the scenes using the Microsoft Graph Explorer.

The Microsoft Graph Explorer lets us talk with the Microsoft Graph, the unified API layer powering most of Microsoft’s products today. It’s targeted at developers but can be very helpful for more advanced citizen development tasks like this one.

Create a Tag and issue a sample message

As a first step, make sure you’ve created a tag inside your sample team. Open that team and manually issue a new message mentioning that tag. This simplifies the lookup of all the IDs later on.

Once you’ve issued the message in Teams, hop over to Graph Explorer and click the Sign in to Graph Explorer button.

On the left side, search for the my joined teams sample query and click Run query. In the response preview, look for the name of your sample team and copy away its id .

Next, search for the channels of a team which I am a member of sample query and replace {team-id} in the URL field with the previously copied id of your sample team and hit the Run query button. When successful, search for your channel in the Response preview and copy the id again.

To find the Tag id, we need to find the sample message that we issued manually.

For this, search for the messages (without replies) sample query on the left. Then, in the URL field, replace {group-id-for-teams} with your team id and {channel-id} with the channel id and hit Run query.

When successful, the Response preview should list all of your recent messages in that channel, including the one mentioning your tag. Search for that message and copy the tag id . Also, note the mentionText which is the name of your tag.

That’s it. Now you have all the necessary IDs to complete your Cloud Flow like described above.

I hope it helps.

👉,
— Sebastian

Click here for more great blogs.

About the Author:

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

Reference:

Zolg, S. (2021). @Mention a Tag in Microsoft Teams with Power Automate. Available at: https://medium.com/@sebastian.zolg/mention-a-tag-in-microsoft-teams-with-power-automate-d62b82808850 [Accessed: 29th July 2021].

Share this on...

Rate this Post:

Share: