Recently, I spent some time with the wonderful Matt Collins-Jones who helped me build a randomiser for my Beer Bot! We built a Flow that would pop back an image of a random beer! However, we can take this one step further and have the bot spit out a topic at random. I used MCJ’s original flow and built a topic randomiser on top! Let’s take a closer look.
Note – be sure to compose your flow either from within the PVA portal or within the default solution of the environment within which your PVA is built in.
First, we need to compose a random number. I used the rand function and set it to produce a random number between 1 and 3. Your min/max numbers are specified in the parenthesis.
Once we have composed the random number, we’re going to need to assign it to a variable as PVA will only allow you to output a single value. Be sure to name your variable! I chose the name “RandomTopic” and ensured its value was set to the output from our previous compose step.
Next, we’re going to return that variable to the PVA bot.
Now we have a random number from our flow! Time for the magic! Let’s call the flow from inside our greeting topic as an example. The flow can be called from within any of your topics!
Once we have called the action we need to create a condition that checks the output and redirects to a topic associated with that value.
When we test the bot, we’re able to follow the path, showing us the random topic!
We can even go one step further – we can have the bot kick off with a random topic by following instructions in this document!
Now go forth and create fun, interactive chatbots! Don’t forget to tweet your creations at me so I can try them out! Happy botting!