How to create rasa form

Hi there.

I’m almost new in rasa, and now I want to get some data from the user. I understood I have to use rasa form and read the documentation but can’t understand it and form won’t work! I wanted to get username and password.

here is what I did:

I added this code to my actions file:

class Authentication(FormAction):
    """Example of a custom form action"""

    def name(self) -> Text:
        """Unique identifier of the form"""

        return "authentications_form"

    @staticmethod
    def required_slots(tracker: Tracker) -> List[Text]:
        """A list of required slots that the form has to fill"""

        return ["username", "password"]


    def submit(
        self,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[Dict]:
        """Define what the form has to do
            after all required slots are filled"""

        # utter submit template
        dispatcher.utter_template("utter_submit", tracker)
        return []

after that I added these to my domain file:

intents:
  - authentication:
      use_entities: []

slots:
  username:
    type: unfeaturized
    auto_fill: false
  password:
    type: unfeaturized
    auto_fill: false

entities:
  - username
  - password

forms:
  - authentications_form

  actions:
   - utter_submit

templates:
  utter_submit:
  - text: "welcome!"

I added form policy too.

then I used my form to story file like this:

## ask for authentication
* authentication
  - authentications_form
  - form{"name": "restaurant_form"}
  - form{"name": null}

and finally I added some example of calling form to NLU file.now when I start rasa and ask for authentication, rasa will call the form but what’s the next step? how should I get data?

thank’s in advance.

Can you please explain what exactly doesn’t work?

I want to create this conversation:

user: please login to my account

rasa: ok, please give me your username

user: username

rasa: well done, now please give me your password

user: password

rasa does some stuff and says: ok, you are (or are not) authenticate

I followed all steps in rasa form tutorial but can’t handle this conversation.

what doesn’t work?

I send rasa : authenticated me, and rasa will understand it but when I send my username and password after that rasa use fallback policy. how should get slots?

did you annotate your username and password as entities? Otherwise you should use from_text slot mapping. See docs and linked tutorial there for details: Forms

look at this image:

when the user says: I would like to book a …

rasa start asking slots step by step.

I looked for “utter_ask_num_people” one of the required slots that rasa ask for, but it is nowhere in the tutorial and “form bot” example codes! (except in domain file that it is where it has been defined but it’s not used anywhere while the image shows it’s working! how?!) tutorial and codes are not complete, can you give me a complete tutorial for how to use rasa form?

1 Like

utter_ask_num_people is an utterance, therefore it is domain file. It is called by

because slot is num_people at this point

2 Likes

thank you so much, actually, I need just this

Hey, @Ghostvv can you please help me with custom actions. Actually when I train everything goes well but the rasa is not catching the proper response. Commands which are given in rasa docs, I’m using that only so there is not an issue with commands and the terminal. Please check the files and the screenshot for the reference. image actions.py (1.1 KB) domain.yml (686 Bytes) nlu.md (1.9 KB) stories.md (95 Bytes)