Custom slot mapping in rasa 2.x not working

Hi, I came across the issue that writing custom action for slot mapping in form does not work from my side.

To be more specific, I have a form which requires name, mobile and address. Mobile can be filled directly from single entity written in domain.yml, whereas name and address needs validate_ custom action to fill the slots. Even if I override the required_slots, name and address which are supposed to be asked by utter_ are skipped and filled with None, and only mobile is asked.

Related link can be found here

Hi @jhzape :wave: can include the domain.yml file with the form definition?

Hello, here is the relevant part.Screenshot from 2021-01-12 14-36-25 Screenshot from 2021-01-12 14-37-22

Thanks! If you uncomment ADDRESS and NAME in your form the form should prompt you to provide those slots. Are you trying to validate these values meet some criteria after they’ve been provided?

Thanks for the reply. I followed the instruction how to do the custom slot mapping in rasa 2.x and override the required_slot in the custom action.

I would like to combine extracted entities first_name and last_name into NAME which needs custom slot mapping, not easy as it used to be in rasa1.x

You could handle this in the form design and avoid the slot mapping. On your form instead of NAME you can have the following with separate slots for first and last name that are mapped to the correct name entity and role.

      - type: from_entity
        entity: name
        role: first_name
      - type: from_entity
        entity: name
        role: last_name

This will fill first_name and last_name with whatever name is extracted from your entity. If a first or last name is missing then the user would be prompted for that information.

Then you can have a custom action processing the completed form that could access the slots to construct the whole name, which could be something like:

class ActionMakeDelivery(Action):
    """Processes Delivery Form"""

    def name(self) -> Text:
        """Unique identifier of the action"""
        return "action_delivery_form"

    async def run(
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> List[Dict]:
        """Executes the action"""
        full_name = " ".join([tracker.get_slot("first_name"), tracker.get_slot("last_name")])

        dispatcher.utter_message(f"Order placed for {full_name}")

        return [SlotSet("full_name", full_name)]
1 Like

Thank you. The method you proposed is very helpful. However, I still have a question regarding how to prompt the user nicely after activating the form. As far as I know, the response utter_ask_<slot_name> is used to prompt the user for the next required slot value, and how should i ask “what is your name” instead of “what is your first name” ? Besides, the same issue happened also to ADDRESS, since I would like to make it consist of street, zipcode and city.