Introduction to adaptive cards

Adaptive Cards are self-contained user interface components that transcend platform boundaries. Crafted in JSON format, these snippets of UI can be seamlessly exchanged between applications.

Upon reaching a particular application, the JSON content is dynamically rendered into native UI elements, seamlessly blending with the app's aesthetic. This approach facilitates the creation and seamless integration of lightweight UI elements across diverse platforms and frameworks.

User story

We're preparing to implement a leave approval workflow in Teams utilizing adaptive cards. Employees will submit their leave requests, and line managers will receive notifications within Teams.

Design the adaptive card

Before establishing the flow, let's initiate the card design process using the designer tool to ensure readiness. Visit https://adaptivecards.io/designer/ to access the designer interface and adjust the 'host app' setting to Microsoft Teams – Light / Dark. Once the card example is updated, we can proceed with development.

New card fact set-

Navigate to https://adaptivecards.io/designer and in Card Payload Editor upload the below JSON.

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "Container",
            "style": "emphasis",
            "items": [
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "Column",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "size": "Large",
                                    "weight": "Bolder",
                                    "text": "**New Leave Request**"
                                }
                            ],
                            "width": "stretch"
                        },
                        {
                            "type": "Column",
                            "items": [
                                {
                                    "type": "Image",
                                    "url": "https://adaptivecards.io/content/pending.png",
                                    "altText": "Pending",
                                    "height": "30px"
                                }
                            ],
                            "width": "auto"
                        }
                    ]
                }
            ],
            "bleed": true
        },
        {
            "type": "Container",
            "items": [
                {
                    "type": "ColumnSet",
                    "columns": [
                        {
                            "type": "Column",
                            "items": [
                                {
                                    "type": "TextBlock",
                                    "size": "ExtraLarge",
                                    "text": "@{triggerOutputs()?['body/Title']}",
                                    "wrap": true
                                }
                            ],
                            "width": "stretch"
                        },
                        {
                            "type": "Column",
                            "items": [
                                {
                                    "type": "ActionSet",
                                    "actions": [
                                        {
                                            "type": "Action.OpenUrl",
                                            "title": "View Item",
                                            "url": "@{triggerOutputs()?['body/{Link}']}"
                                        }
                                    ]
                                }
                            ],
                            "width": "auto"
                        }
                    ]
                },
                {
                    "type": "FactSet",
                    "spacing": "Large",
                    "facts": [
                        {
                            "title": "Submitted By",
                            "value": "**@{triggerOutputs()?['body/Author/DisplayName']}** @{triggerOutputs()?['body/Author/Email']}"
                        },
                        {
                            "title": "Employee",
                            "value": "@{triggerOutputs()?['body/Title']}"
                        },
                        {
                            "title": "Start Date",
                            "value": "@{triggerOutputs()?['body/StateDate']}"
                        },
                        {
                            "title": "End Date",
                            "value": "@{triggerOutputs()?['body/EndDate']}"
                        }
                    ]
                }
            ]
        },
        {
            "type": "Container",
            "items": [
                {
                    "type": "ActionSet",
                    "actions": [
                        {
                            "type": "Action.Submit",
                            "title": "Approve",
                            "style": "positive",
                            "data": {
                                "id": "@{triggerOutputs()?['body/ID']}",
                                "action": "approve"
                            }
                        },
                        {
                            "type": "Action.ShowCard",
                            "title": "Reject",
                            "style": "destructive",
                            "card": {
                                "type": "AdaptiveCard",
                                "body": [
                                    {
                                        "type": "Input.Text",
                                        "id": "RejectCommentID",
                                        "placeholder": "Please specify an appropriate reason for rejection.",
                                        "isMultiline": true
                                    }
                                ],
                                "actions": [
                                    {
                                        "type": "Action.Submit",
                                        "title": "Send",
                                        "data": {
                                            "id": "@{triggerOutputs()?['body/ID']}",
                                            "action": "reject"
                                        }
                                    }
                                ],
                                "$schema": "http://adaptivecards.io/schemas/adaptive-card.json"
                            }
                        }
                    ]
                }
            ]
        }
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.2",
    "fallbackText": "This card requires Adaptive Cards v1.2 support to be rendered properly."
}

Building the flow

Complete Flow

Complete flow-

Thank you