Graph API MS Teams Power Automate
Manish Solanki  

How to send inline image in MS team message using power automate?

Use Case

There is a size limit of 28 KB when we post a message on MS teams using power automate. But recently, I came across a new action “Send a Microsoft Graph HTTP request” that can be used for overcoming this limit. Using this action, we can easily post a message with inline images over 28 KB.

Scenerio

We have an image store in SharePoint ‘Site Assets’ library which will be posted on MS teams channel in the form of card:

Solution

1. Start with getting the content of the file from SharePoint library using “Get file content” action. I have hardcoded the file path but you can make it dynamic based on the use case:

2. Next, add two more actions to get the ids of Teams & Channel respectively. Add “Get team” action and select the team’s name from the dropdown. Post that, add “List channels” action to return the array or list of channels for a team.

3. To filter a channel from the “List channels” action, we will use “Filter array” action to get a particular channel. We will filter the channel by name using filter query. Pass the channel list from the output of previous action by selecting from dynamic window:

Click ‘Edit in advanced mode’ button on the bottom of filter array to enter the below filter query in the textbox:

@equals(item()?['displayName'], 'General')

Please note that I am posting card in ‘General’ channel, but you could modify the channel name as per the need.

4. Finally, we will use “Send a Microsoft Graph HTTP request” action to post a message with inline or embed image. We will be setting the teams & channel id dynamically. In the body, we need to pass the base64 content string along with content type of the hosted content. The maximum possible size of hosted content is 4 MB:

URI:
https://graph.microsoft.com/v1.0/teams/@{outputs('Get_a_team')?['body/id']}/channels/@{first(body('Filter_array'))?['id']}/messages


Method:
POST


Body:
{
	"body": {
        "contentType": "html",
        "content": "<div><div>\n<div><span><img height=\"297\" src=\"../hostedContents/1/$value\" width=\"297\" style=\"vertical-align:bottom; width:297px; height:297px\"></span>\n\n</div>Good Morning!</div>\n</div>"
    },
    "hostedContents":[
        {
          "@microsoft.graph.temporaryId": "1",
          "contentBytes": "@{body('Get_file_content')?['$content']}",
            "contentType": "@{body('Get_file_content')?['$content-type']}"
        }
    ]
}


Content-Type:
application/json

Output

Conclusion

Using “Send a Microsoft Graph HTTP request” action, we can directly call the graph apis for teamwork & communication space without using premium connector (Entra connector). As explained in this article, we can use the same action for posting message to overcome the message size limit of 28 kb. This action can be used for performing action which otherwise would not be possible with standard actions of the Microsoft teams connector like sending multiple inline images etc.

3 thoughts on “How to send inline image in MS team message using power automate?

  1. […] Send inline image in MS team message using power automate (manish-solanki.com) […]

  2. Bharadwaj

    Can we use this method to post message in group chat too ?

    If so can you please help with URI ?
    Thanks.

  3. Bharadwaj

    Can we also do the same for a group chat ?
    If so can you please share the URI for group chat ?

    Nice work. Appreciated mate.

Leave A Comment