How to launch a different story based on a slot value

Hello dear Rasa Community,

I made a new rasa project with a very simple story just to try if I’m capable to launch a different scenario based on a slot value. I will share my little code and then I’ll explain.

stories.yml:

version: "3.1"
stories:
- story: Interview
  steps:
  - intent: greet
  - action: utter_greet
  - action: action_select_random_story

actions.py:

class ActionSelectRandomStory(Action):
    def name(self) -> Text:
        return "action_select_random_story"

    def run(self, dispatcher, tracker, domain) -> List[SlotSet]:
        # Define a list of pre-defined story names
        story_number = [True,False]

        # Randomly select a story name from the list
        number = random.choice(story_number)
        print(number)
        SlotSet("story_number", number)
        # Set the selected story as the active conversation story
        return [SlotSet("story_number", number)]

rules.yml:

version: "3.1"

rules:
- rule: shared_questions_1
  condition:
  - slot_was_set:
    - story_number: true
  steps:
    - action: utter_1
    - intent: one
    - action: utter_goodbye

- rule: shared_questions_2
  condition:
  - slot_was_set:
    - story_number: false
  steps:
    - action: utter_2
    - intent: two
    - action: utter_goodbye

So now that you have read the code, what am trying to do is basically randomly have my custom action returning True or False and based on that two scenarios are possible:

  • “shared_questions_1” is triggered with the slot story_number = true
  • “shared_questions_2” is triggered with the slot story_number = false

The issue is none of the rules seem to be triggered even though the slot value is being allocated to the slot (I checked the logs).

What I have tried so far to fix this issue is:

  • Implemented the rules as stories instead
  • Used categorical slots instead of bool and with values [1,2] instead of [true,false]

It would be really helpful if anyone knows how to fix this or if anyone has any suggestion to achieve what I’m trying to achieve. Thanks in advance.

@SheninFrancies Hey there I feel like you’re on of the most knowledgeable people around this forum. Can you give it a quick read and see if there’s something you can help me out with? It would be really appreciated