Here’s how you can use Power Automate to randomly select an image or GIF and post it in a Microsoft Teams message.

Screenshot of sending a randomly selected image/GIF in Teams

You will first need the URL of the images or GIFs you would like to use. When the flow is run, one will be randomly selected and posted in a Microsoft Teams chat.

In this example, I’ve selected the following 5 GIFs from https://giphy.com/sunnyfxx/

To get the URL, you will need to right click on the image/GIF and select Copy image address.

Get the URL of your image or GIFs

In your flow, add in the action Initialize variable with the following values:

Name: randomgif
Type: Array
Value: Here you will need to paste in the URLs of your GIFs/images. They will need to be in the format of [“URL1”, “URL2”, “URL3”, “URL4”, “URL5”]

Screenshot of your flow action: Initialize variable

Next, add in the Microsoft Teams action Post a message in a chat or channel. The Post as and Post in values can be up to you. In the Message field, type in your message (if required) then click on the code view button.

Screenshot of your Microsoft Teams flow action. Show code view for the message.

On a new line, type the following:

<img src=”EXPRESSION”>

Screenshot of your flow Teams action. Enter in the text.

Backspace the word EXPRESSION and replace it with the following expression. You may need to type it out rather than copy and paste if you receive an error.

variables('randomgif')[rand(0, length(variables('randomgif')))]
Screenshot of your flow Teams action. Enter in the expression.

The expression should be in between “” without any spaces.

Screenshot of your flow Teams action once complete

Save the flow and it is ready to go. Run the flow to see it in action.

4 thoughts on “Send a random image or GIF with Power Automate

  1. Hi, nice article, that is i was searching,
    I have applied this method in my workflow but it is not posting gifs there,
    it is posting like this “![]https://www.funimada.com/assets/images/cards/big/bday-643.gif”
    please help me in this regard.
    thanks in advance!

  2. Awesome article! unfortunately my MS teams chat is just posting the URL not the gif. in a manual test I did the manual try and if I copy a gif from chat to chat it works if I copy it to word I get the URL, if I paste the URL into chat I get the url, not the gif, so I think my company may have some unknown security I’m not privy to. Although right clicking on the URLs of the GIFs included in our teams chats I get the link to the terms of service from the giphy.com website. totally bummed because this would be super cool. Anyhow thanks for sharing AND congrats on the MVP!!

    1. Hi Sheryl, you could try out the new designer for your bot. It makes it easier to add gifs in your chats, just by adding in the link. So no work around of building a flow first. I have info here on how to find it https://rishonapowerplatform.com/2022/11/20/power-virtual-agents-unified-canvas-overview-of-changes-and-new-features/ (see the “Media” section). However, it’s currently a feature that can’t be used with existing bots, you’ll need to create a new one.

      And thanks!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s