How to do preliminary operations in forms

So, let’s say that the user asks something that requires the activation of a form.

Before starting with the form, I want to check if some slot is set or not. If it’s set I will go on with the form, otherwise I will return some error message and deactivate the form.

How can I perform that?

you can create different stories where if the slot is set, the form is predicted, otherwise smth else

Can you give me an example of that? How can I check in my stories if a slot is set or not?

And btw… what if I need to run some python code before the form starts? There must be a way to insert some code just before the first utter_ask is triggered…

Did you manage to do this? I have the same question

Hi @teresalazar13,

as documented here you can define a slot as featurized (meaning that the slot will influence the prediction behaviour hence the storyline.

An example for this is:

# story_01
* greet
  - action_fetch_profile
  - slot{"account_type" : "premium"}
  - utter_welcome_premium

# story_02
* greet
  - action_fetch_profile
  - slot{"account_type" : "basic"}
  - utter_welcome_basic

This is a categorical slot - based on its value different actions are predicted. For your example you could go with:

# story_01
* intent{"your_slot":"any_value"}
   - restaurant_form
   - form{"name": "restaurant_form"}
   - form{"name": null}

# story_02
* intent
  - utter_deny_form_procedure

If - as you have mentioned - the check should lay inside the form itsself, I’d suggest to overwrite the run - method of the rasa_sdk inside your form:

def run(
    dispatcher: "CollectingDispatcher",
    tracker: "Tracker",
    domain: Dict[Text, Any],
) -> List[EventType]:
    """Execute the side effects of this form.

Here you can check with the tracker.get_slot(…) method, what should happen.

Did that help?

Kind regards

1 Like

Thank you! That’s what I needed! :slight_smile: