Need Help Implementing Random Path Selection in a Chatbot

Hi everyone,

I’m currently working on a chatbot using the Juji platform and I’m facing a challenge that I could use some help with. Here’s the scenario:

The chatbot will request an input from the user. After receiving this input, the chatbot should randomly select one path from a pre-defined set of paths. Each path represents a distinct conversation, structured in a step-by-step manner. For example:

  • Path 1: Message 1.1 → Message 1.2 → Message 1.3 → …
  • Path 2: Message 2.1 → Message 2.2 → Message 2.3 → …
  • Path 5: Message 5.1 → Message 5.2 → Message 5.3 → …

Once the path is randomly selected, the chatbot should send the messages to the user following the order in the chosen path.

I’m struggling with implementing the random path selection and ensuring the chatbot follows the selected path correctly. The selection of the path is not influenced by the user’s input, it should be purely random. I am not using the Juji API or any other external APIs, I am doing all of this within the Juji platform.

Has anyone faced a similar situation or does anyone have any ideas on how I could approach this problem? Any guidance or resources would be much appreciated!

Thank you in advance!

1 Like

Hi,

One way to do this is using “customize chatbot actions” and preconditions.

  1. Use Post-action to assign an random value to attribute e.g. “random-path” using the Clojure function rand-nth to randomize the selection within a list of values.

  2. Create your messages 1.1, 1.2 … 2.1 … 5.1… in order. Add precondition to all messages such that for every message in path n, it has precondition Attribute randome-path is = n. e.g. the message 2.3 should have Attribute randome-path is = 2 in its precondition, where as the message 4.1 should have Attribute randome-path is = 4 in its precondition.

Hope this helps!

1 Like