Rasa is not triggering the custom form action

I’m creating a survey bot in Rasa and I’d like it to trigger a function in the actions.py file when it receives a response on one of the form slots. I tried following the instructions for the extract_ slot method in the documentation, but something isn’t working. Here is my code from the domain and actions (the function in actions that it should trigger is list_tasks_numbered_names when the experience_dose slot is filled).

So long as I fill the appropriate intents, the form continues filling the slots, but it just doesn’t trigger anything in actions.py

Thank you and please let me know if I can make this question more clear

ACTIONS

class ValidateExperienceForm(FormValidationAction):
    def name(self) -> Text:
        print ('experiece form triggered')
        return "validate_experience_form"
    

    async def required_slots(
        self,
        slots_mapped_in_domain: List[Text],
        dispatcher: "CollectingDispatcher",
        tracker: "Tracker",
        domain: "DomainDict",
    ) -> Optional[List[Text]]:
        required_slots = slots_mapped_in_domain
        return required_slots

    async def extract_experience_dose(
        self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict
    ) -> Dict[Text, Any]:
        print ('experiece form triggered under async')
        text_of_last_user_message = tracker.latest_message.get("text")
        
        tasklist = list_tasks_numbered_names(text_of_last_user_message)

        #tasklist = '"' + tasklist + '"'
        resp = "Here is your task list: \n"+str(tasklist)
        
        print ('DEBUG: this is the task list', tasklist)
        
        
        
        #dispatcher.utter_message('here is a list of tasks to choose from', tasklist)
        dispatcher.utter_message(resp)
        return [SlotSet('experience_dose', tasklist)]

DOMAIN

experience_form:
    required_slots:
      experience_substance:
      - type: from_text
        not_intent: bogusintent
        value: false
      experience_dose:
      - type: from_text
        not_intent: bogusintent
        value: true
      experience_insight:
      - type: from_text
        intent: inform
        value: true

DId you add validate_experience_form into domain.yml -> actions ?

1 Like

Very helpful! It’s triggering the action.py, but it’s running the entire function for every slot. How do I just run the function for this specific slot step? Thank you!

I can think of three ways to do it:

  1. In the extract_xxx function , you can add an addition. if slot.get......
  2. Make it to validate_xxx function
  3. Remove experience_dose from required_slots.
1 Like

So helpful! I tried the if slot.get solution but got two problems:

  1. It’ triggers the if statement on subsequent slots. It should only happen for one thought

  2. I encountered another issue: the Slotset function stopped working. Here is my normal code, which gets a list of items from a function (list_tasks_numbered_names):

The line return [SlotSet('asana_select_options_slot', tasklist)] doesnt set the slot with tasklist. Something going with this loop?

Here’s how i implemented your solution below:

if tracker.get_slot('experience_dose'):
            text_of_last_user_message = tracker.latest_message.get("text")
        
            tasklist = list_tasks_numbered_names(text_of_last_user_message)

            resp = "Here is your task list: \n"+str(tasklist)
        
            print ('DEBUG: this is the task list', tasklist)
            dispatcher.utter_message(resp)
            return [SlotSet('asana_select_options_slot', tasklist)]