With Power Virtual Agents, it is possible to return a GIF or an image to the conversation via Power Automate. This post will take you through the steps of how you can use Power Automate to randomly select one of your curated images or GIFs, then send it to the conversation with the end user in Power Virtual agents. It’s an easy way to add some variety to your chatbot conversations.

Related posts:
Take your chatbot to the next level with images and GIFs
Send a random image or GIF with Power Automate

Screenshot of the PVA demo website with a randomly selected GIF

1. Collect the URLs of the images and GIFs you would like to use

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 to your bot.

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

2. “Call an action” to your Power Virtual Agent and create the flow

In the conversation tree of your topic in PVA, select the Call an action node for Power Automate. Create a new flow.

Screenshot of PVA: Create a flow within your topic

In your flow, add in the action Initialize variable after the trigger. Set 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 Power Automate: Initialize variable action

Expand Return value(s) to Power Virtual Agents. Click +Add output and select Text. Enter selectedgif as the title of the output.

Screenshot of Power Automate: Add an output

In the selectedgif output field enter in the following:


Screenshot of Power Automate: Enter the output value

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 Power Automate: Enter expression in the output value

The expression should be in between () without any spaces.

Screenshot of flow output action

Save the flow and return to Power Virtual Agents.

3. Connect your flow to your topic

Back in your PVA topic, add the flow you just created into the conversation.

Screenshot of PVA: Add in your flow

Add a new message node underneath.

Screenshot of PVA: Add a message node

Within the message node, insert the selectedgif variable.

Screenshot of PVA: Add selectedgif variable in message node

It is now ready to test. Save your topic and test your bot!

Screenshot of PVA: Testing bot

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