Find the intent name in Custom Action

I have a custom action in which I’m calling a slot value to be filled with user text. I want to extract the intent name from the text because the user can type anything in the textslot and if he goes out of scope I need to send a do you want to continue action

Is there a way to do this?

Hey @anoopshrma, try this!

class Action_test(Action):
def name(self):
    return 'action_test'

def run(self, dispatcher, tracker, domain):
    intent = tracker.latest_message['intent'].get('name')
    ...
return []

Hope this helps your need.

Hi @shiva_sankeerth,

Yes it would tell me the latest intent value but I’m trying to get the intent from the text which user typed in the slot.

For example let’s just say that the story goes like this

Bot: how was your day

User : cricket is best ( user typed this in slot )

Now I want to find the intent of this text

Hey @anoopshrma,

I think you can use the form validation feature of rasa for doing this.

class ValidateCarServiceForm(FormValidationAction):
    def name(self) -> Text:
        return "validate_car_service_form"
    
    def validate_car_brand(self,slot_value: Any,dispatcher: CollectingDispatcher,tracker: Tracker,domain: Dict[Text, Any]) -> Dict[Text, Any]:
        """Validate car_brand slot value."""

        if slot_value.lower() == 'bmw':
            return {"car_brand": "BMW"}
        else:
            return {"car_brand": slot_value.title()}
        
    
    def validate_city(self,slot_value: Any,dispatcher: CollectingDispatcher,tracker: Tracker,domain: Dict[Text, Any]) -> Dict[Text, Any]:
        """Validate city slot value."""

        return {"city": slot_value.title()}

The above class will validate each slot when the user fills it. Here, car_brand and city are my slots. You can customise this to your own need.

This is official link to the documentation Forms

Hey @shiva_sankeerth,

But will it tell me the intent label of the text? For example

If I want to know the intent label of the text which user typed in the slot. How can I do that

I am stuck in similar problem. Did you get a way to find out intent of text entered by user?

Hi @rupesh2306,

You can get the intent of the text with the following inside the validation method or in run method

        # latest_message is `parse_data`,
        # which is a dict: {"intent": UserUttered.intent,
        #                   "entities": UserUttered.entities,
        #                   "text": text}

        text_Intent = tracker.latest_message.get("intent")
1 Like