Create Alert Notifications with Preview Messages in Microsoft Teams Using Workflows webhooks

The perfectly functioning Office 365 connectors are being discontinued... The webhooks which you could generate and be up and running in a couple of minutes to receive alerts on your monitoring will soon be 'retired' as per the following notification:

Office 365 Connectors within Teams will be retired soon. The Workflows app provides similar functionality with more scalability and security. Learn More.
Note: To manage existing connections, please open Connectors page in
Teams web client.


What's the replacement you may ask? Well that would be Teams Workflows... And rather irritatingly, it is not as straight forward to get back up and receiving alerts because MS has not considered a template to give out notifications. 

Let me explain:

Select the 3 dots in the channel you want to receive alerts on (I'm doing this to the General channel), select workflows:


Select All Templates:


Find the following to get notifications from a webhook to a Teams channel



Configure the following with your Teams channel details



Copy the webhook link and paste in your Grafana or whatever app that is sending the POST.

I'm using this for my Grafana and as seen below I'm able to get notifications on my General Teams Channel. 





You may think that was easy as the Office365 connectors method, but here's the catch:

Notification in Activity feed just shows 'Card'



Also there is no notification message preview




Things are worse on the MS Teams mobile side. Your phones notification panel will be filled with 100s of  meaningless messages all saying 'Card'. You have to click on it and go all the way into the channel to see what's what!

As an admin this will make your life extremely unpleasant in case you are monitoring multiple environments and you get dozens of notifications throughout the day and you do not have that 'at a glance' information.

Luckily for you, I have managed a small workaround to get that same notification behavior as in Office365 Connectors.


To do this you need to edit the default workflow from power automate to support notification previews. The default notifications are sent as card types. This needs to be changed to message.

You can easily access this by going to channel workflows page and select one of the events from the run history as follows:


You can also access this from Power Automate in Office365


The flows you created from Teams per channel should be visible in Cloud Flows. Select your desired flow and edit.



The default flow will appear as follows:


You need to modify this:

Right click and delete the highlighted steps

It should look like this:


Click the + icon and add ‘Post message in a chat or channel’



In parameters set your channel details

In the body click on fx and set the following 






concat(
  if(
    contains(
      triggerBody()?['attachments']?[0]?['content']?['body']?[0]?['text'],
      '[RESOLVED]'
    ),
    '🟢 <span style="color:green"><b>',
    '🔴 <span style="color:red"><b>'
  ),
  triggerBody()?['attachments']?[0]?['content']?['body']?[0]?['text'],
  '</b></span>',
  decodeUriComponent('%0A%0A'),
  triggerBody()?['attachments']?[0]?['content']?['body']?[1]?['text']
)

Click add and the following will appear



Finally click save button on the top right







0 Comments