Microsoft Power Automate: Post Adaptive cards to a Microsoft Teams for an Approval
Post Adaptive cards to Microsoft Teams for Approval using Power Automate
In this article, we are going to see how to create a flow that posts adaptive cards to a Microsoft Teams channel.
To demonstrate, I have taken a simple scenario of post sick leave request adaptive card to my manager for approval via Microsoft team and based on the approval/reject response the email sent to me. Before we start with flow steps. Let’s know about the adaptive cards and Microsoft Teams connector.
Overview of Adaptive cards:
Adaptive Cards are a platform-agnostic method of sharing and displaying blocks of information without the complexity of customizing CSS or HTML. Adaptive cards in JSON format, with integration that cloud apps and service can openly exchange. When delivered to a specific app, the JSON is transformed into a native UI that automatically adapts to its surroundings. It helps design and integrate lightweight UI for all major platforms and frameworks.
Adaptive cards help you integrate into exiting apps like Outlook actionable message, Window timeline, Microsoft teams, and Bot Framework.
Using Adaptive card designer editor, you can easily configure and design an adaptive card. Each adaptive card has its own page with a title, description, chart, images, buttons, etc.
Once an adaptive card design is completed, copy the actual JSON that you can include in Microsoft power automate.
Microsoft Teams connector:
Before choosing the Microsoft Teams connector, we need to decide whether we are going to post adaptive cards to a Microsoft Teams channel, or to Microsoft team members.
Directing Adaptive cards to Teams members:
- Post your own adaptive card as the Flow bot to a user: This action posts an adaptive card as a Flow bot to a specific user. In this case, you will need to provide a recipient email address, and the card will show up in the recipient's chat and/or activity feeds during the flow run. There is no requirement for the user to be part of a Teams instance to receive these types of Adaptive Cards. In this case, only the URL button functions by redirecting to the URL that's configured within the flow.
Directing Adaptive cards to Teams channels:
- Post your own adaptive card as the Flow bot to a channel: This action posts an adaptive card as a Flow bot to a specific Teams channel. In this case, you will be prompted for Teams instance and a channel where the card will be posted. The flow-maker will have to have access to the Teams instance in order to post an adaptive card there. In this case, only URL button functions by redirecting to the URL configured within the flow.
- Post an adaptive card to a Teams channel and wait for a response: This action posts an adaptive card as a specific Teams channel as in the case above. However, in this case, the flow will not continue until someone on the channel has responded to any inputs required within the card. The flow will continue once the anyone in the Teams channel responds but will only return dynamic content for one (1) response per responder and per card.
Let’s see the Flow steps,
Step #1:
Whenever I’m not feeling well and require a few days of leave to take rest, I will manually trigger the flow to submit a leave request to my manager. So, I’m going to use a manual trigger template as a first step.
Step #2:
In the second stage, we are going to create approval content like title, assigned to, details, and attachment (link to the item to approve). So, I have chosen the Create an Approval template and configured the required information.
Before continuing to configure essential information. Let’s know about the Create an approval template.
Create an approval card is a template for the approval request that’s sent to approvers. Configure it in a way that’s useful for your approver.
Moreover, create an approval action provides several tokens, including Responses and Outcome. Use these tokens to run an approval request flow.
Approval type: When a flow with Create an Approval action is configured with Approve/ Reject – First to respond, it waits until assigned to approve or assigned to rejects the approval request.
Title: Request for sick leave.
Assigned To: My manager's email address.
Details: Addition information that you want to be sent to the approver.
Item link: If you have any document in SharePoint then share URL for the approval.
Item link description: Addition information about the shared document.
Requestor: I have added dynamic content like User email which gives the email address of the person who is manually triggered the flow.
Most importantly Create an approval action, create an adaptive card based on configuration information.
In the next step, we are going to select the Microsoft Teams Connector!
Step #3:
I have chosen Microsoft Teams connector “Post your own adaptive card as the Flow bot to a user”. As per our scenario, we are going to post sick requests to my manager. So, Post your own adaptive card as the Flow bot to a user connector director our adaptive card to Team members. We need to choose a connector.
As per our scenario, a sick leave approval request is posted to my manager. So, I have chosen “Post your own adaptive card as the Flow bot to a user” Microsoft Teams connector. This connector directs the adaptive card to concerned members.
Recipient: my manager's email address is configured.
Message: we have passed the adaptive card which is created in the previous step.
Step #4:
Approver receives adaptive card approval request in Microsoft Teams. Meanwhile, the flow needs to wait until approver responds to our request. The Response can be either approved or rejected. So, I have used Wait for an Approval template which halts the flow until approver responds to our request.
Approval ID: I have added dynamic content like Approval ID which gives the ID of the approval.
Step #5:
To evaluate the approver response then we need to add a condition to a flow. Chose a condition action
On the condition card, select an empty area in the box on the left. The dynamic content list opens. Select the Outcome parameter to add it to the box.
In the box in the middle of the condition card, select is equal to
In the box on the right, enter the Approve text.
Step #6:
Based on the approval response, we need to send an email to the requestor.
If the response to the request is Approve, you might want to send an email to the requestor. With email contain:
Subject: Sick leave is Approve
Body: Approved
If the response to the request is Reject, we might want to send an email to the requestor. With email contain:
Subject: Sick leave is Reject
Body: Rejected
Well, that’s it, we’re done Save the Flow.
Let’s test the flow
Our flow will trigger manually. So, I have triggered the flow by clicking the Run flow button.
Immediately Sick leave adaptive card request is posted to my manager in Microsoft Teams and waiting for a response:
Based on my manager approval, our flow will immediately capture the response and send the email to the requestor.
If my leave request is approved by my manager, then an approved email is sent to me
Similarly, if my leave request is rejected by my manager
Then, the flow will immediately send a reject email to me.
Perhaps, this article will also give you some inspiration on other ways to make use of Power Automate.
Thanks for reading!
*This post is locked for comments