Is there a way to create a story that handles not intent logic?

Suppose I have an intent named affirm which consists of all types of “yes”.

Now i want to create a story where if the user says anything except “yes”, i wish to utter a different bot message.

Eg:

## example story
* !(affirm)
  - utter_bot_message

Is there anything like this available in the framework?

1 Like

@GauravRoy48 When you say anything except “yes” can it be classified as any other intent that is part of your bot, or it doesn’t belong to any intent? Also, may I know your use case for which you would need this?

It may or may not be classified as any other intent. For simplicity’s sake, lets assume that the user response can be classified as some other intent.

My use case is that the bot has asked a yes/no question, and i want the user to stick to only answering in yes or no. Any other intent will make the bot ask the same question again. Since I have almost 50 intents and I’m still only 30% done with adding intents, I wanted to know if there is a easy way to handle this instead of leaving it up to rasa’s probabilistic model.

You can use a form:

    class FormYesNo(FormAction):
    	def name(self):
    		return "form_ys"
    		
    	@staticmethod
    	def required_slots(tracker):
    		return ["yn"]
    		
    	def slot_mappings(self):
    		return { "yn": [self.from_intent(intent="affirm", value=True), self.from_intent(intent="deny", value=False), self.from_intent(not_intent=["affirm", "deny"], value='other')]}
    	
    	def validate_yn(self, value, dispatcher, tracker, domain):
    		if value == 'other':
    			dispatcher.utter_message("Please, answer the question.")
    			return {"yn": None}
    		else:
    			return {"yn": value}
    	
    	def submit(self, dispatcher, tracker, domain):
    		yn = tracker.get_slot("yn")
    		if yn:
    			#do something
    			return[SlotSet('yn', None)]
    		else:
    			#do something
    			return [SlotSet('yn', None)]

Write your original question in the domain file, for utter_ask_yn. Because the way forms work in rasa, this method will repeat the original question after the “Please, answer the question.” message is sent.

1 Like