Navigate back to the homepage

Manual Intervention Steps in Azure Logic apps with MS Teams

John Kilmister
September 5th, 2021 · 4 min read

It is possible in both Power Automate and Azure logic apps to interact in a range of ways with Microsoft Teams. One of the new additions, is the ability to add in an action step which posts a prompt into Microsoft Teams. The logic app will wait for the users response and then continue based on the reply.

In this post we will run through a demo of an Azure logic app looking first at a simple plain text integration then at a richer solution using adaptive cards.

Design

Ideally, we want to avoid manual steps whenever possible in our applications but sometimes only a human can decide. It is possible to use a Condition action block and prompt only when a condition is met, however in this post we are going to use a simpler flow to demonstrate the processes needed.

In this demo we will configure a http trigger, prompt the user to select the request as either high or normal priority then add the request to the relevant message queue.

Initial Trigger

The Microsoft Teams steps can be integrated with any of the available triggers however we will start by using a simple json payload posted to a http trigger.

1{
2 "name": "Sam Green",
3 "message": "Urgent, needed for today report pack",
4 "uri":"https://files.blueboxes.co.uk/34324.json"
5}

Prompting Options

Adding a new action block to your logic app, first search for Microsoft Teams and then select the Post a choice of options as the Flow bot to a user action. Like many connectors the first use will prompt authorisation, in this case with your Microsoft Teams account.

Screenshot of Azure Website showing the option to select

This action block will allow you to enter the options you wish to the user to select from, along with a instructional message. The message can contain data from the initial trigger or any earlier steps if needed, as shown here.

Screenshot of Azure Website showing the details to enter

This action block can only post to a single user, so we enter their email address. You could change this to be a variable or other input if you need it to be more dynamic.

When running, this will then be shown to the user in Microsoft Teams. Once the user has selected an option then control is returned back to the logic app.

Screenshot of Azure Website showing the option to select

Taking Action

We can now add a switch action block to decide how to progress based on the users selection. Into the On we will use the selectedOption from the value returned from the Microsoft Teams action block.

Screenshot of Azure Website showing the option to select

Finally, we can add the action to take for each path. In this case it is simply adding the request on to a message queue for later processing.

Adaptive Cards

Adaptive cards allow us to design our own card layouts that can be shown to the user. These can include forms, images, and action buttons. The website adaptivecards.io has many examples of different cards and includes a designer at adaptivecards.io/designer. Once you have built your card in the designer you can copy the JSON and use it in your logic app.

It is worth noting at this time the adaptive cards must be a maximum version 1.2 format and do not support data binding when working with teams through logic apps.

Adaptive Card Prompting

We will replace the Post a choice of options as the Flow bot to a user block with a Post adaptive card and wait for response block.

The first change is that this now provides extra options such as posting in to a channel or group chat in addition to sending directly to a user.

This time instead of a message and options we will design a simple adaptive card and paste in the JSON in to the message field. The card will have action buttons that include json data that is sent back once selected.

1{
2 "type": "AdaptiveCard",
3 "body": [
4 {
5 "type": "TextBlock",
6 "text": "Message From @{triggerBody()?['name']}",
7 "size": "Medium",
8 "weight": "Bolder",
9 "wrap": true
10 },
11 {
12 "type": "TextBlock",
13 "text": "@{triggerBody()?['message']}",
14 "wrap": true
15 }
16 ],
17 "actions": [
18 {
19 "type": "Action.Submit",
20 "title": "High Priority",
21 "data": {
22 "Priority": "High"
23 }
24 },
25 {
26 "type": "Action.Submit",
27 "title": "Normal Priority",
28 "data": {
29 "Priority": "Normal"
30 }
31 },
32 {
33 "type": "Action.Submit",
34 "title": "Do not Process",
35 "data": {
36 "Priority": "None"
37 }
38 }
39 ],
40 "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
41 "version": "1.2"
42}

When this is posted in Microsoft Teams it will be presented like shown below. The design I have created means it does not look much different at the moment. As these are now adaptive cards however you can become much more creative and include images, other options, receive user input and return richer data.

Screenshot of Azure Website showing the option to select

Finally the action block returns a data that contains JSON rather than plain text. This can be parsed using a Parse JSON action block before the conditional block is then updated to now use the parsed values rather than the plain text selectedOption.

Timeouts

Behind the scenes these blocks use a webhook callback from Microsoft Teams. When we run the logic app we will see that in the portal the step is shown as waiting.

Screenshot of Azure Website showing the details to enter

It will stay as waiting until the callback is made after the user has chosen a response. This will eventually time out if a reply is not received. I could find limited information on this but the default timeout could be as long as 30 days.

Screenshot of Azure Website showing the timeout error

The good news is that you can set the timeout to your own value in ISO 8601 format under settings in the step menu behind ... A value such as PT30M would provide a timeout of 30 minutes.

Screenshot of Azure Website showing the timeout settings

If the timeout is reached the logic app will be marked as failed. You can manage this by creating a new step and selecting configure run after under the ... menu. From this you can then select for the this new step run to only run after a timeout preventing the failure.

Summary

Although we want to avoid manual intervention it is sometimes required for a human to decide.

In this post we looked at the changes to the Microsoft Teams connector and the Post a choice of options as the Flow bot to a user action block. Using this it is possible to prompt a user in Microsoft Teams then act on the choice. We then looked at how we can use adaptive cards to enhance the experience and base our actions on this.

For more information see the official documentation https://docs.microsoft.com/en-us/connectors/teams/

Title Photo by Jon Tyson.

If you enjoyed reading please share...

More articles from John kilmister

How to Create Azure Resource Graph Explorer Scheduled Reports and Email Alerts

Azure has many ways to be notified of activity from budget alerts to Azure Monitor Alerts each of which can attach to action groups using…

August 15th, 2021 · 2 min read

Getting Started with Serverless SignalR and Azure Functions

SignalR provides the ability to push or broadcast information from a back-end server at any time to any front end web application that has…

July 28th, 2021 · 3 min read
Link to $https://twitter.com/johnkilmisterLink to $https://github.com/blueboxesLink to $https://stackoverflow.com/users/33/johnLink to $https://www.linkedin.com/in/johnkilmister/