I want to accept two numbers in a form. It works fine when it fills the slot first time. Next time user asks, it goes back to the question of what is slot_1? Is that a bug?
@staticmethod
def required_slots(tracker: Tracker) -> List[Text]:
return [slot_1", "slot_2"]
def slot_mappings(self) -> Dict[Text, Union[Dict, List[Dict]]]:
return {
"slot_1": [
self.from_entity(
entity="number", intent=["test"]
),
]
,
"slot_2": [
self.from_entity(
entity="number", intent=["test"]
),
],
}
@staticmethod
def is_int(string: Text) -> bool:
"""Check if a string is an integer"""
try:
int(string)
return True
except ValueError:
return False
def validate_slot_1(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
if isinstance(value, list):
if len(value) == 2:
if self.is_int(value[0]) and int(value[0]) > 0 and self.is_int(value[1]) and int(value[1]) > 0 :
return {"slot_1": value[0], "slot_2": value[1]}
else:
return {"slot_1": None, "slot_2": None}
if self.is_int(value) and int(value) > 0:
return {"slot_1": value}
else:
dispatcher.utter_message(text="slot not valid?")
# validation failed, set slot to None
return {"slot_1": None}
def validate_slot_2(
self,
value: Text,
dispatcher: CollectingDispatcher,
tracker: Tracker,
domain: Dict[Text, Any],
) -> Dict[Text, Any]:
if self.is_int(value) and int(value) > 0:
return {"slot_2": value}
else:
dispatcher.utter_message(text="slot2 not valid?")
# validation failed, set slot to None
return {"slot_2": None}
In the submit function: return [SlotSet(“slot_1”, None)] + [SlotSet(“slot_2”, None)]