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:

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.

channelatmentioning_test

The Flow will use a manual trigger. After that the Flow initializes three variables.

Channel post url variables

Channel post url

Just like in John his example I am using the Invoke an HTTP request. This invoke HTTP request uses the ChannelPostUrl variable.

Invoke http request

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 tag. It should be id=\"0\".

The only difference is that the body of the post request.

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.

channelimportant_test

It is very easy. Just set the importance attribute to high.

Happy testing!

You may also like...

11 Responses

  1. Jeremy Gregg says:

    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!

  2. Matt says:

    Jeremy, I ran into the same thing. You need to alter the escape characters from the sample:

    “content”: “These ones -> Around me”,

  3. Andrey says:

    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.”

  4. Dennis says:

    @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 🙂

  5. Jonathan Cavey says:

    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

  6. Dennis says:

    @Jonathan,good question. Haven’t tried that before. I will test it soon 🙂

  7. Kondal says:

    @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”
    }
    }
    }
    ]
    }

  8. Dennis says:

    @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

  9. Anu C. says:

    thank you for sharing. I followed the example above with the graph api and it worked.

  10. Sig says:

    what about authentication? It asks me for an access token

  11. Brett says:

    Is there any way to do this without Azure AD premium?

Leave a Reply

Your email address will not be published. Required fields are marked *

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