IBM Watson Assistant: How to get random responses in the new Action skills

Viewed 119

In the Watson Dialog there is an option to generate multiple responses randomly. Allowing it to feel less robotic.

Picture of the UI showing 3 random text messages

In the new Actions skills they do not have this option. Is there a way to reproduce it?

1 Answers

If you have simple one line responses then the following code snippet will work in a response.

<? {
0: "Message 1",
1: "Message 2",
2: "Message 3"
}[new java.util.Random().nextInt(3)]
?>

The 3 in nextIt(3) must be the total number of random responses.

If you have more detailed responses to give then you can assign a context variable a value of java.util.Random().nextInt(3) (again changing 3 to total responses). Then use that as a conditional in the steps.

New Actions steps showing messages

Related