Microsoft Flow/Power Automate: Post to Teams channel

Microsoft Flow/Power Automate: Post to Teams channel
Microsoft Flow/Power Automate: Post to Teams channel

Posting automatically to a Teams channel can help you increase efficiencies big time. E.g. if you want to update your colleagues or friends on a daily basis about certain events or you want to use an event based trigger like when a new deal is closed this can help you do all of it automatically without your intervention.

In this scenario I am using a recent idea in our company to post a "happy week meme" every Monday to create some fun and some excitement at the beginning of the week.

In order to achieve this, the following setup is done:

  1. Excel with the information about the meme to be shared
  2. MS Flow to gather the data and to post it in a teams channel
  3. The colleagues to enjoy the meme

Setting up the Excel for the content to post

The first step is to setup the Excel for the content which should be posted. The Excel has the following columns:

  1. ID: The id of the column, this is auto-calculated based on the year, month and day of the date column. This is necessary as it is easier to compare later in the flow. The assumption in this scenario is that there is at max 1 post per day.
  2. Date: The date when the content should be posted
  3. Message: The message of the post
  4. Image URL: The URL to the meme to be posted

00---Excel-base-data

Setting up the Microsoft Flow to post the content to a teams channel

The next step is to set up the flow. It will have three steps:

  1. Start the flow based on a trigger
  2. Check for available content for the day and load it
  3. Post the content to a teams channel

Start the flow based on a trigger

There are several triggers you can choose to start a flow. In this case the best trigger is a daily run of the flow. To configure a daily trigger, select a Recurrence trigger and set it up to run daily. Select Day in Frequency and then choose the days you want the flow to run.

Check for available content for the day and load it

In this step the flow checks for available content of today and loads it to use it in the post. To achieve this the "Get a row" action for MS Excel works best.

In the "Get a row" action you need to define the following attributes:

  1. Location: The location where your Excel is saved
  2. Document Library: The document library where your Excel is saved
  3. File: The path to the file
  4. Table: The table to use in the Excel
  5. Key Column: The key column in the table (here it is the described ID column in the previous section)
  6. Key Value: The value of the key to lookup. I am using the following formula for the Key Value: `formatDateTime(utcNow(), 'yyyy-M-d'). This has to match with the formula you use in the Excel to calculate the ID.

The result is an object you can use at later stages, if there is no value available for the key, the flow fails which is fine as you do not want to do any action then. Of course you can handle this error, which is not covered in this post.

Post the content to a teams channel

The last step is to post the content to a teams channel. For this you use the "Post message in a chat or channel" action. You have to set the following attributes:

  1. Post as: By whom is the content posted. I have selected Flow bot here, you can also choose User. This means that your user is posting the content then.
  2. Post in: Where you want to post your content, here it is a Channel.
  3. Team: The Teams team you want to post your content in.
  4. Channel: The channel you want to post your content in.
  5. Message: The message you want to post. Flip this to "source mode" and edit the HTML as below to post the message as well as the picture.

The result of your MS Flow post to a teams channel

That's it. Pretty straight forward and easy to implement. The result in my case looks like this: