October 13, 2024

Microsoft Teams is the tool today for interaction with co-workers, but it can be overwhelming when the channels are popular, and people are active. So automating some tasks is essential to save you precious time. That’s where the “When a new channel message is added” trigger comes into play.

Let’s check how to use it.

Where to find it?

You can search for the “When a new channel message is added” trigger to find it.

Otherwise, you can go to the “Standard” tab and select “Microsoft Teams”.

Pick the “When a new channel message is added.”

Here’s what it looks like.

Pro Tip:
Power Automate tends to save the most common triggers on the main screen, so check there before going through the full hierarchy. Also, you can use the search to find it quickly.

Usage

There’s not much to configure on the “When a new channel message is added” trigger. You only need to point it to the Team and Channel, and it will start listening to messages added in Teams.

Outputs

The trigger returns a lot of information in a JSON format, although the conversion from JSON is done automatically for you. Here’s an example:

{
    "headers": {
        <redacted>
    },
    "body": {
        "@odata.type": "#microsoft.graph.chatMessage",
        "etag": "1633358608128",
        "messageType": "message",
        "createdDateTime": "2021-10-04T14:43:28.128Z",
        "lastModifiedDateTime": "2021-10-04T14:43:28.128Z",
        "importance": "normal",
        "locale": "en-us",
        "webUrl": "<redacted>",
        "id": "16",
        "from": {
            "user": {
                "id": "a10c6616-fe65-4f4d-acd6-9af1a991b9c4",
                "displayName": "Manuel Gomes",
                "userIdentityType": "aadUser"
            }
        },
        "body": {
            "contentType": "text",
            "content": "test message"
        },
        "channelIdentity": {
            "teamId": "10566946-2522-11ec-9621-0242ac130002",
            "channelId": "19:5c8@thread.skype"
        },
        "attachments": [],
        "mentions": [],
        "reactions": []
    }
}

The “When a new channel message is added” trigger will return quite some information. We’ll ignore the headers since it’s information that we don’t need, but the “body” produces a lot of helpful information like:

  1. The message was posted.
  2. The channel’s ID
  3. Attachments
  4. Mentions
  5. Reactions

It’s a lot, and depending on what you want to do, they can be more or less helpful.

I have a real case of this trigger into action on my “Add Attachments to Microsoft Planner from Teams” article.

I want you to understand that:

  1. The trigger contains the added attachments when posted.
  2. The reactions field will only contain the reactions since the message was posted until the trigger fires. After that, it’s not time, so you can consider the value empty most of the time.
  3. The attachments field will contain the URL to the attachment and not the contents.

Limitations

The trigger will only fire for messages, not replies. For example, if you do this:

Recommendations

Here are some things to keep in mind.

Don’t use it for “busy” channels.

Although Power Automate can cope with millions of triggers, your subscription won’t. So you’ll run through your quota quickly, which is a problem. Also, if the channel is super busy with many messages, the Flow will trigger a lot so keep this in mind when using this trigger.

Keep it short

Since Teams can have a lot of messages, it’s good to keep the Flow as lean as possible. If the Flow runs frequently and takes a long time, you’ll have the following:

  1. A long list of running Flows
  2. If they update the same data source, you’ll have conflicts because you can’t guarantee who will edit it first.
  3. If you’re updating your systems, they will be under heavy load since Flow will trigger frequently.

You should constantly think about what your Flow is doing and if your actions and systems can cope with frequent calls to avoid downtime in critical systems.

Never generate the Team or Channel ID.

You should never generate IDs manually. There isn’t even a good reason to do it since it’s a trigger, and there’s no logic that you can “calculate” before.

Tools change, and IDs change with them. So you should never have even to know the ID of a Team or Channel.

Finally, having the IDs will make debugging more challenging because you need the description of the Team to guide you. If you see, “Sales” is much nicer than “9a9bcb24-f32c-4fe9-839c-9d709c10b4fe”.

Name it correctly

The name is super important since we can get the trigger from anywhere and with anything. Always build the word so others can understand your use without opening the action and checking the details.

Always add a comment.

Adding a comment will also help to avoid mistakes. Indicate your expectations, why the Flow should be triggered, and the data used. It’s essential to enable faster debugging when something goes wrong.

Back to the Power Automate Trigger Reference.

Photo by Jason Leung on Unsplash

Manuel Gomes

I have 18 years of experience in automation, project management, and development. In addition to that, I have been writing for this website for over 3 years now, providing readers with valuable insights and information. I hope my expertise allows me to create compelling, informative content that resonates with the audience.

View all posts by Manuel Gomes →

2 thoughts on “Power Automate: Teams – When a new channel message is added Trigger

  1. Another thing to watch out for is that this is a “polling trigger” which means that if you disable the flow temporarily, or if it is disabled automatically due to some error occurring, when you enable it again it will run through all the messages that arrived in the channel while it was off and try to process them. This could lead to a flurry of unwanted actions. Microsoft’s advice (which seems pretty terrible to me) is that you need to delete and recreate the flow entirely to only pick up messages from now onwards.

    1. Indeed and that advice to me is not viable.
      I suggest as a failsafe to add validation after the trigger where, if the date of the post is greater than a few hours, for example, it won’t proceed. In this case it needs to be something that makes sense in your case.
      It’s not ideal, but it’s better than re-creating the Flow.
      Do you have another workaround that you do in this case?

Leave a Reply

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

Mastodon