How to send random GIFs via Power Virtual Agents
Barhead Solutions
Multi-award-winning Microsoft partner specializing in cloud business solutions across a range of industries.
How can you make chatbot conversations feel more like you’re talking to an actual person? One way to add a bit of variety to chatbot conversations is to have your virtual agent send random GIFs to users. Using Power Automate and Virtual Agents, you can set your chatbot to send GIFs from a selected collection. Here’s how you can do that:
1. Collect the URLs of the images and GIFs you will 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. You can get sample GIFs from this website: https://giphy.com/sunnyfxx/. To get the URL, you will need to right-click on the image/GIF and select Copy image address.
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 and create a new flow. 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”]
Expand Return value(s) to Power Virtual Agents. Click +Add output and select Text. Enter selectedgif as the title of the output. In the selectedgif output field, enter in the following: . Afterwards, replace the word EXPRESSION with the following expression: variables(‘randomgif’)[rand(0, length(variables(‘randomgif’)))]. Save the flow and then return to Power Virtual Agents.
Note: You may need to type it out rather than copying and pasting it if you receive an error. Also, keep in mind that the expression should be in between () without any spaces.
Read more here.