How to take an input from the user and save it in a slot

I think the solution here is using forms. I recommend to read the doc since it’s a bit specific. To my humble opinion Rasa is missing some easy to use catch-all action out-of-the-box.

But in general,

  • You make a form in your domain.yml:
slots:
  my_slot:
    type: text
    mappings:
    - type: custom

forms:
  my_form:
    required_slots:
    - my_slot
  • Create a custom form validation action. Apart from the forms doc, you can read about it here or check out rasa forum questions like this one.
from rasa_sdk.forms import FormValidationAction

class ValidateMyForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_my_form"

    def extract_my_slot(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]):
        # Code here
        return {"my_slot_name": something}

    def validate_my_slot(self, value: Text, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any]):
    # Code here
  • After that you can read stories/rules like that:
- story: my_story
  steps:
  - intent: my_intent
  - action: utter_something
  - action: my_form_name
  - active_loop: my_form_name
  - slot_was_set:
    - requested_slot: my_slot_name
  - active_loop: null
  - action: some_other_action