cancel
Showing results for 
Search instead for 
Did you mean: 
Priyaranjan

Render Adaptive Card Images from SharePoint Library using Power Automate

Priyaranjan_7-1647965324069.png

 

Introduction

Adaptive cards give us the option to share information in a platform agnostic way using JSON. In our previous articles we did see how we can share basic Adaptive cards into Microsoft Teams using Power Automate. In this article we will see how we can extent the implementation by adding images to the card.

Images can be rendered in multiple ways in the adaptive card like:

  • Store in SharePoint Document library and use the Base 64 image content in Card
  • Use Direct URL to a publicly hosted file within the card. But do note that, you will have to test this scenario thoroughly as not all direct links would work as expected. Direct shareable links in Onedrive/SharePoint and some of the Image hosting sites don’t render in the cards
  • Store Image in Azure Storage and use the image content in the card.

In today’s article we will see how to use an image stored in SharePoint and render it within the adaptive card.

Use Case

 

I have uploaded an image to the Document Library which I would want to use as the Header or Banner of the Good Morning Message that goes out to the users. To achieve this we will use a scheduled Flow that runs everyday at a specified time and picks the image from the library to form the header of the card and add the good morning wish just below the image resulting in a simple Wish Card to start off the day

 

Implementation

 

Let’s use the recurrence trigger to start off with the scheduled flow.

Priyaranjan_0-1647965114535.png

 

We will then get the Banner/Header image which is stored in the library using Get File action

 

Priyaranjan_1-1647965114538.png

 

Since the image content is returned as an object, we will use the compose action and use the below expression to convert it to a base64 string

 

 

 

base64(outputs('Get_file_content')?['body'])

 

 

 

Priyaranjan_2-1647965114544.png

 

Final step is to create the JSON that we will use in the Adaptive card and we can do this using the Adaptive card designer

As we can see we have just 2 elements in the JSON:

  • Image : That holds the Header Banner image from SharePoint Library
  • RichTextBlock : Which contains the morning wish message

Adaptive Card JSON

 

 

 

{
    "type": "AdaptiveCard",
    "body": [
        {
            "type": "Image",   
           "url": "data:image/png;base64,@{outputs('Compose_-_Convert_Image_to_Base_64')}",
           "horizontalAlignment": "Center"
        },
        {
            "type": "RichTextBlock",
            "inlines": [
                {
                    "type": "TextRun",
                    "text": "Hello Priyan, Good Morning !",
                    "size": "Large",
                    "weight": "Bolder"
                }
            ],
            "horizontalAlignment": "Center"
        } 
    ],
    "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
    "version": "1.2"
}

 

 

Priyaranjan_3-1647965114552.png

 

Thus the overall flow would look like below :

 

Priyaranjan_4-1647965114558.png

 

 

Test the flow

 

Since it is a scheduled flow, we will do a manual trigger to test the flow. It will pick the Banner image from SharePoint Library, create the adaptive card using the JSON payload and sent it to Teams Chat.

 

Priyaranjan_5-1647965114562.png

 

Note :

At times if the total JSON payload is over 28KB it will throw the below error and it could be because of the size of the image you are using.

 

Priyaranjan_6-1647965114563.png

 

This is by design and there is no way as of now to work around the payload and the Engineering team is working on this. In such a situation an easy workaround would be to use a tool like this to bring the Image size below 20Kb.

Summary

 

Thus we saw how to use an image stored in SharePoint as a banner in the adaptive card that we sent to Microsoft Teams

 

 

Comments
About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/