I am beginner and trying to implement form actions. I’m validating my slots where everything is working fine however when my slot validation fails, the failed message as well as the next utter message is displayed multiple times. once i fill in the valid data the slots are getting filled. Functionality wise its working fine but i don’t want the utter messages to be displayed multiple times.
define the name of the method
def name(self) -> Text:
return "validate_ticketExtraction_form"
define the required slots
@staticmethod
def required_slots(tracker: Tracker)->List[Text]:
#print("required_slots(tracker: Tracker)")
return ["xx" , "yy"]
define the slot-intent-entity mapping
def slot_mappings(self):
#type: type()-> Dict[Text: Union[Dict, List[Dict]]]:
"""A dictionary to map required slots to
- an extracted entity
- intent: value pairs
- a whole message
or a list of them, where a first match will be picked"""
return {"xx": self.from_entity(entity="xx",
intent="xxExtraction"),
"yy": self.from_entity(entity="yy",
intent="yyExtraction")}
define the validation criteria for the slots
def validate_xx(
self,
slot_value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate maildata value."""
if <condition>:
# validation succeeded, set the value of the "cuisine" slot to value
return {"xx": slot_value}
else:
# validation failed, set this slot to None so that the
# user will be asked for the slot again
dispatcher.utter_message(text="The given input is not as per the standard criteria")
return {"xx": None}
def validate_yy(
self,
slot_value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: DomainDict,
) -> Dict[Text, Any]:
"""Validate ticketnum value."""
if <condition>:
# validation succeeded, set the value of the "ticketnum" slot to value
return {"yy": slot_value}
else:
# validation failed, set this slot to None so that the
# user will be asked for the slot again
dispatcher.utter_message(text="The given input is not as per the standard criteria")
return {"yy": None}
define the final action during performing
def submit(self, dispatcher, tracker, domain):
# type: (CollectingDispatcher, Tracker, Dict[Text, Any]) -> List[Dict]
"""Define what the form has to do
after all required slots are filled"""
# utter submit template
dispatcher.utter_message(text="Submiting Form! ")
return []
stories:
version: “2.0”
stories:
- story: happy path
steps:
- intent: greet
- action: utter_greet
- intent: emailExtraction
- action: ticketExtraction_form
- active_loop: ticketExtraction_form
rules:
rule: activate ticket extraction form steps:
-
intent: emailExtraction
-
action: ticketExtraction_form
-
active_loop: ticketExtraction_form
-
rule: submit form condition:
- active_loop: ticketExtraction_form steps:
- action: ticketExtraction_form
- active_loop: null
- slot_was_set:
- requested_slot: null
- action: utter_submit
Any help here would be appreciated!! Thanks in advance. Output screenshot below: