Random response to user in a personal assistant


I’m create a personal assistant, to help anyone that uses a PC to execute some task in Windows.

First the bot ask user about her name. and then ask a user for what action should be execute.

In the activity, I use the command IF, in this form.

IF variable1action.Contains(“E-mail”), the bot open a email and ask if should send a email.

My question is, have any method to bot response a user with random response?

For example. If user uses a variable the bot can’t recognize, the bot should response user with a message like “Sorry, I can’t do this”, but if the user insists on error, the bot can change the response for not be the same every time?

Anyone can help me?

You can create an Array or DataTable to hold the various responses. Then use System.Random to generate a random number for the number of responses you have. Use the random as an index to obtain a random response from the Array or DataTable.

For example:

Responses = {"Hello!", "Hi, there!", "Bonjour!", "Hi!"}
r = New Random()
RandomResponse = Responses(r.Next(0, 4))

Hope that helps!

Hello, thank you for your answer.

U can send me a example, please?

Sure. See attached.
image RandomGreeting.zip (9.8 KB)

1 Like

Hello my friend!

It’s awesome your answer, but I can’t reproduce on my example.

On the box “B” on first Assign (Create array of greetings), the UiPath are mark my Value with invalid sentence.

U can help me?

Check the source files in the ZIP attachment.

The Greetings variable type needs to be an Array of Strings.