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

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/
- https://media4.giphy.com/media/MYCg1AoPwiSuDuD13O/giphy.gif
- https://media1.giphy.com/media/RhHqv0oKyc9dkjHwLn/giphy.gif
- https://media.giphy.com/media/W2bxebmDd8s1yrO8aT/giphy.gif
- https://media.giphy.com/media/5UFK2tqEqpeCyadiuV/giphy.gif
- https://media.giphy.com/media/ZbfOV3d6iAT5VoHsoj/giphy.gif
To get the URL, you will need to right click on the image/GIF and select Copy image address.

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”]

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.

On a new line, type the following:
<img src=”EXPRESSION”>

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')))]

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

Save the flow and it is ready to go. Run the flow to see it in action.
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!
Would be good to see a picture of your flow. Drop me a message on LinkedIn (https://www.linkedin.com/in/rishonaelijah/) with some screenshots of your flow so I can see what might be wrong
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!!
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!