diff --git a/rasa_sdk/forms.py b/rasa_sdk/forms.py index 008e0bc17..636bd7fac 100644 --- a/rasa_sdk/forms.py +++ b/rasa_sdk/forms.py @@ -153,7 +153,7 @@ async def get_validation_events( slots.pop(slot_name) continue - method_name = f"validate_{slot_name.replace('-','_')}" + method_name = f"validate_{slot_name.replace('-','_').replace('.', '_')}" validate_method = getattr(self, method_name, None) if not validate_method: diff --git a/tests/test_forms.py b/tests/test_forms.py index 433e06882..0d819e5e6 100644 --- a/tests/test_forms.py +++ b/tests/test_forms.py @@ -12,7 +12,6 @@ ) from rasa_sdk.slots import SlotMapping - DEFAULT_DOMAIN = { "slots": { "some_other_slot": { @@ -759,9 +758,9 @@ async def extract_my_slot( (["my_slot", "other_slot"], {}, [SlotSet(REQUESTED_SLOT, "other_slot")]), # Extract method for slot which is also mapped in domain ( - ["my_slot"], + ["my_slot", "other_slot"], {"forms": {"some_form": {"required_slots": ["my_slot"]}}}, - [], + [SlotSet(REQUESTED_SLOT, "other_slot")], ), ], ) @@ -874,3 +873,50 @@ async def required_slots( dispatcher = CollectingDispatcher() events = await form.run(dispatcher=dispatcher, tracker=tracker, domain=domain) assert events == expected_return_events + + +async def test_form_validation_space_slot(): + form_name = "some_form" + + class TestFormValidationSpaceSlotAction(FormValidationAction): + def name(self) -> Text: + return form_name + + def validate_space_slot( + self, + slot_value: Any, + dispatcher: "CollectingDispatcher", + tracker: "Tracker", + domain: "DomainDict", + ) -> Dict[Text, Any]: + if slot_value == "correct_value": + return { + "space.slot": "validated_value", + } + return { + "space.slot": None, + } + + form = TestFormValidationSpaceSlotAction() + + # tracker with active form + tracker = Tracker( + "default", + {}, + {}, + [SlotSet("space.slot", "correct_value")], + False, + None, + {"name": form_name, "is_interrupted": False, "rejected": False}, + "action_listen", + ) + + dispatcher = CollectingDispatcher() + events = await form.run( + dispatcher=dispatcher, + tracker=tracker, + domain={"forms": {form_name: {"required_slots": ["space.slot"]}}}, + ) + assert events == [ + SlotSet("space.slot", "validated_value"), + ]