Optional slotting filling

does anyone have a working example on optional slot filling preferably using FormAction?.

Edit: For example, required_slots = [‘account_number’, ‘transaction_id’, ‘confirm_account_number’ , ‘confirm_transaction_id’,‘date_of_transaction’ ]

but i need account_number or transaction_id along with date_of_transaction to respond. depending on available slot (account_number or transaction_id), confirm_account_number or confirm_transaction_id are also optional.

Hi @ramreddymettu hope it helps and you can also check the documentation for more details and example form the repo.

class LocationIDForm(FormAction):
    def name(self):
        # type: () -> Text
        """Unique identifier of the form"""
        return "location_id_form"
    
    @staticmethod
    def required_slots(tracker):
        return ['lat', 'lng']
    
    def slot_mappings(self):
        return {
            "lat": [self.from_entity("lat", intent="select_location")],
            "lng": [self.from_entity("lng", intent="select_location")]
        }
    
    def validate_lat(self, value, dispatcher, tracker, domain):
        if value == None:
            return None
        return {"lat": value}

    def validate_lng(self, value, dispatcher, tracker, domain):
        if value == None:
            return None
        return {"lng": value}

    def validate(self, dispatcher, tracker, domain):
        lat = tracker.get_slot('lat')
        lng = tracker.get_slot('lng')
        if lat == None and lng == None:
            dispatcher.utter_template('utter_please_share_location', tracker)
        return []

    def submit(self, dispatcher, tracker, domain):
        lang = tracker.get_slot('language')
        directions = ActionGetDirection() 
        directions.run(dispatcher, tracker, domain)
        return []

Cheers

Thank you for the quick response. But this is an example of FormAction with mandatory slots [‘lat’, ‘long’]. I think my question is not clear, I’m looking for a FormAction or Action which can handle slots optionally.

For example, required_slots = [‘account_number’, ‘transaction_id’, ‘confirm_account_number’ , ‘confirm_transaction_id’,‘date_of_transaction’ ]

but i need account_number or transaction_id along with date_of_transaction to respond. depending on available slot (account_number or transaction_id), confirm_account_number or confirm_transaction_id are also optional.

Hi, sorry to miss that, maybe you can try to use the validate function? You can make some logical process there,

def validate_transaction_id(self, value, dispatcher, tracker, domain):
    if tracker.get_slot('account_number') != None:
        return {"account_number": ""}
    #or you need to validate the value again then return it
    return {"account_number": value}

and vice versa for validate_account_number