Mention a channel with Flow
Twitter is always great for the latest information on the Microsoft stack. But it is also great for inspiration from the community. Lately I have been following John Liu his Flow hacks. His tweet inspired me to create an at mention channel Flow example.
What the hack?
One of the things which was challenging in Flow was the use of the Microsoft Teams post message action. I have been struggling with this action to use for more advanced things like at-mentioning.
And then I saw this tweet from John:
Hack #FlowNinja 94 @MicrosoftFlow at-mentions in post message to @MicrosoftTeams
at-mentions isn’t possible with the current post message, but can be done since the update to MSGraph API (ex 2) https://t.co/St6VzxgHtt
call this with HTTP with AzureAD premium action pic.twitter.com/VGNTn3zCzj
— John Liu ? (@johnnliu) May 10, 2019
At-mention channel
My first attempt was of course to test his solution, which worked great. After that I wanted to try something different. I created a Flow which at-mentions the whole channel.
The Flow will use a manual trigger. After that the Flow initializes three variables.
Just like in John his example I am using the Invoke an HTTP request.
First make sure that you the Invoke an HTTP request action connection is using https://graph.microsoft.com as the Base Resource URL and Azure AD Resource URI values like in the screenshot below.
After you have done that you can use the ChannelPostUrl variable for the URL of the request and the code snippet below for the body.
Update 28-06-20: The following code snippet, has a small quote typo. The code widget I am using in this blog adds additional quotes. For some reason it has to many quotes to the channel id reference in the id=\"0\"
.
Update 25-06-21: The following code snippet was invalid since a couple of days. pchaturvedi85 made me aware of that on GitHub.
Update 19-09-21: Thanks to Vlad and Josh for pointing out I accidently removed the conversationIdentityType property. Updated the codesnippet again.
Mark as important
While testing with the body of this request I was wondering if I could also make a message important. I know it is not directly related but it has a similar markup style in Microsoft Teams.
It is very easy. Just set the importance attribute to high.
Happy testing!
HI – thanks for this post – really helpful.
I’ve implemented it for one of my Teams sites, but I keep getting an error: “Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.”
The only thing I’ve changed vs. your code is that I’ve substituted my channel name in place of “SharePoint Site Collections” in your code. I’m sure the JSON is correct therefore – so, can this error thrown for some other reason?
Hope you can help!
Jeremy, I ran into the same thing. You need to alter the escape characters from the sample:
“content”: “These ones -> Around me”,
I did not understand. Could you clarify please what characters and from where should I alter?
Still have the same error: “Unable to read JSON request payload. Please ensure Content-Type header is set and payload is of valid JSON format.”
@Jeremy & @Andrey,
I think there is a small typo in the code snippet. For some reason it has added to many quotes to the channel id reference in the tag. It should be
id=\"0\"
. I tested the json code snippet in the Graph Explorer, https://developer.microsoft.com/en-us/graph/graph-explorer.This is probably a good place to test this kind of json code snippets 🙂
Hello @Dennis, is there any way to do this within a adaptive card within flow? I for some reason can not use the method you have posted. Thank you
@Jonathan,good question. Haven’t tried that before. I will test it soon 🙂
@Jeremy @Dennis
I’m new to this . Not sure what I’m doing wrong
When i run this by updating my channel name i get the error as teamGroupId needs to be a valid GUID.
I even tried running with the ID manually but it still failed.
{
“body”: {
“content”: “This is Flow mention channel test, General”,
“contentType”: “html”
},
“mentions”: [
{
“id”: 0,
“mentionText”: “General”,
“mentioned”: {
“conversation”: {
“id”: “5a99a50fxxxxxxxxxxxxxxx”,
“displayName”: “General”,
“conversationIdentityType@odata.type”: “#Microsoft.Teams.GraphSvc.conversationIdentityType”,
“conversationIdentityType”: “channel”
}
}
}
]
}
@Kondal, what’s your ChannelPost Url value?
Structure should be something like this:
https://graph.microsoft.com/v1.0/teams/{team-id}/channels/{channel-id}/messages
So for example:
https://graph.microsoft.com/v1.0/teams/81bf333c-xxxxx-xxxx-xxxx-xxxxxxxxxx/channels/19:xxxxxxxxxxxxxxxxxxxxxxx@thread.tacv2/messages
thank you for sharing. I followed the example above with the graph api and it worked.
what about authentication? It asks me for an access token
Is there any way to do this without Azure AD premium?
Super rookie here but eventually got it to work !! Thanks for this !!
Wondering if it’s also possible to use it to (1) Reply to a conversation (Like Post a reply to a message V2 (Preview) and (2) post the message as the flow bot ?
hi @Dennis,
thank you for your tips and code for this.
I just want to be sure am I missing something – I did this as you did, it works, the mentioning is posted in the channel but what I want to know is this:
1. Is it me or the notifications for your channel mention method are not working, or that’s not working because of MS still?
2. If they should be working , what am I doing wrong?
Thanks,
Niksa
Hi Dennis,
Thanks for your sharing!
But I faced an issue to authenticate, error saying: Access token validation failure. Invalid audience.
What I got from response was: Bearer realm=””, authorization_uri=”https://login.microsoftonline.com/common/oauth2/authorize”, client_id=”00000003-0000-0000-c000-000000000000″
It seems we did not setup logon directing in this flow, is it meant in Azure? Then could you advice how we should do it?
Thanks~!
Carol
is it possible to work without autorization&
How would you include a [today’s date yyyy-mm-dd] variable in the json file as a subject line for the message? Is this possible?
Realize you can probably just do today’s date as another variable.
Hi Dennis,
Power Automate has started throwing “Invalid request body was sent.” message since June 18th 2021. Do you know of any changes Microsoft may have done to the graph api that’s making the header invalid?
Thanks,
Prashant
Hi Dennis, I have been using this for months and it works great, but just this morning it comes up with an error:
Error: Action ‘Invoke_an_HTTP_request_2’ failed
Error details: Invalid request body was sent.
Any suggestions for this? Thanks!
@Prashant & @Keegan,
The codesnippet is invalid now because the schema has changed.
pchaturvedi85 made me aware of that:
https://gist.github.com/expiscornovus/bc7953b79faba66e0cb7d09a47d2f026#gistcomment-3791644
A followup, you should not remove “conversationIdentityType”: “channel” param it is valid MS Graph resource type https://docs.microsoft.com/en-us/graph/api/resources/teamworkconversationidentity?view=graph-rest-1.0 if you remove it breaks the experience, you won’t be able to click on mentioned channel and got to channel. Because by default “conversationIdentityType”: “team” not a channel and it tries to look for a name of teams vs. provided channel.
Having just gone through this process, I want to clarify Vlad’s above point. He is saying you should remove
“conversationIdentityType@odata.type”: “#Microsoft.Teams.GraphSvc.conversationIdentityType”
but NOT
“conversationIdentityType”: “channel”
The block that works for the current implementation/schema is as follows:
{
“id”: 0,
“mentionText”: “General”,
“mentioned”: {
“conversation”: {
“id”: “5a99a50fxxxxxxxxxxxxxxx”,
“displayName”: “General”,
“conversationIdentityType”: “channel”
}}}
Hi Josh, thanks for spotting that error.
You and Vlad are right, I think I removed a bit too much after the last adjustment 🙂
Hello
Is it possible to do the same thing inside an Adaptive Card.
I tried to mix your way + this link (https://docs.microsoft.com/en-us/microsoftteams/platform/task-modules-and-cards/cards/cards-format?tabs=adaptive-md%2Cconnector-html#format-cards-with-html) but it doesn’t work…
Hi Charlélie,
I haven’t tried mentioning a channel in an adaptive card, I will have a look. I did try mentioning a user in an adaptive card:
https://www.expiscornovus.com/2020/11/15/how-to-create-a-terms-of-use-message/
Maybe that blog helps you get started?
Hi Dennis,
Have you tried mentioning teams tag in an adaptive card?
This is great! Thank you very much for this information, very appreciated.
Thank you for this! I’ve noticed that unfortunately it doesn’t actually generate a notification for the user. The “Mention” link does take me to the correct channel, but doesn’t add anything to the activity pane 🙁
Have you been able to make that part work? The same code does notify a user when you tag them directly.
Hi all,
It is possible tag a channel team if the Channel Name include “&”? I tried and I achieve in a channel without “&” in the name but when I tried to implement the same in a group with “&” in the channel name I couldn’t. I really appreciate your assist. thanks in advance
Hi all,
Unfortunately the Invoke an HTTP request action is part of the PREMIUM features on my Power Automate, which I don’t have access to.
Any alternatives to this action that I could use?
The only similar action I could find was “Send an HTTP request to SharePoint” but it is requesting a Site Address which not sure what should I input in…
Hi Mariano,
You can try and use the Send an HTTP request action of the Office 365 Groups connector. That one is non-premium.
Hi Does any one know how to include a hyperlink in the content? I am using the Send an HTTP request (Office 365) which is working but i need to include a clickable URL in the Teams Channel when mentioned.
Hi Melissa,
The content property supports the usage of HTML. So, you could use the a tag. Only thing you need to be mindful of is that you escape the quote characters.
I have created a new sample for you which includes a hyperlink:
Hi, this forum has been so educational. thank you so much. I require a little bit of assistance. I am trying to incorporate an image into my teams message using power automate but I get an error where the payload is greater than 28kb.
So, I tried to use the method above but for an image. The image is saved in a folder in sharepoint. Unfortunately, even though the flow runs successfully I cannot see the image. It shows the icon when you cant view an image.
The help would be most appreciated it. Thanks
I wish we can do the same with posting message on a group chat (not just channel).
Hi Joe,
That should also be possible. Use for example the below setup
URI
Body