Running a form in the middle of another one

Hi there. I’m new to Rasa and so far loving it.

A special case I came across is that when user is filling a form(call it form A), it is asked if he is qualified for plan Foo. User can answer with yes/no/I’m not sure. Which can be handled by buttons easily.

If user chooses “I’m not sure”, I need to start another form(call it form B) which when filled will let the user know if he is qualified for plan Foo. Then I need to get back to form A and continue.

Is there any way to do this. Starting form B in the middle of form A can be done using rules. But how can I get back to form A again. Form B can also be started directly, so the chatbot should only get back to A if user started with the form A and not always.

Any help or idea is appreciated.

Hi! :blush:

I don’t know it’s possible maybe @ChrisRahme can explain it better for us.

Mayber can try using condition. Checking slots are filled when back to form A

But, why you not putting together? Form A and form B and using conditionals in stories

I think this example - inancial-demo can help you

I would suggest the same as @itsjhonny. Use one form, and implement dynamic behavior to change the slots according to given conditions.

Thanks you and @ChrisRahme very much for your answers.

Switching between forms in the financial bot using conditions and saving previous form seems great if I can get it to work with my own case. I will try that.

Dynamic behavior could work as well and is actually my personal favorite but since my form A is decision tree like form, where each new question depends on previous answer, it is already a bit complicated (specially for non-coders in the team), mixing it with another form might get it too complicated and hard to maintain. Specially since form B can be called using other means as well.

This is exactly a use-case I worked with, so what I did is build a database of questions and what their follow-up question would be depending on the condition and build a for loop accordingly, using if for special cases (see example line 1197).

Of course, you can all hardcode it with ifs only as I did before using that database (see example line 1025).

Thanks, that is very helpful specially with example code.

Hi am experiencing trouble implementing the dynamic behavior. Here is my code

class ValidatehivNotPregForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_hivNotPreg_form"

    async def required_slots(
        self,
        slots_mapped_in_domain: List[Text],
        dispatcher: "CollectingDispatcher",
        tracker: "Tracker",
        domain: "DomainDict",
    ) -> Optional[List[Text]]:
        additional_slots = []
        if tracker.slots.get("hivMeds") is True:
            additional_slots.append("howMedsStored")
            additional_slots.append("hivMedsEnv")
        else:
            additional_slots.append("timeMedIntake")
        return slots_mapped_in_domain + additional_slots

    async def extract_howMedsStored(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> Dict[Text, Any]:
        howMedsStored = tracker.get_slot("howMedsStored")
        return {"howMedsStored":howMedsStored}

    async def extract_timeMedIntake(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> Dict[Text, Any]:
        timeMedIntake = tracker.get_slot("timeMedIntake")
        return {"timeMedIntake":timeMedIntake}

     async def extract_hivMedsEnv(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> Dict[Text, Any]:
        hivMedsEnv = tracker.get_slot("hivMedsEnv")
        return {"hivMedsEnv":hivMedsEnv}

Whenever the condition is satisfied in the if statement and the slot “howMedsStored” is filled, I would expect to proceed to another additional slot, but “howMedsStored” is still uttered to infinity. Can someone please help we solve this, been stuck for days.