From 9301a57377b4c24b8390f005a11c245be6638236 Mon Sep 17 00:00:00 2001 From: alwx Date: Tue, 16 Jun 2020 14:07:47 +0200 Subject: [PATCH 1/2] RulePolicy: scope dispatches per form --- rasa/core/actions/forms.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/rasa/core/actions/forms.py b/rasa/core/actions/forms.py index 2d21744d0882..5bd92fd8302f 100644 --- a/rasa/core/actions/forms.py +++ b/rasa/core/actions/forms.py @@ -462,17 +462,24 @@ async def request_next_slot( # no more required slots to fill return [SlotSet(REQUESTED_SLOT, None)] - @staticmethod + def _name_of_utterance(self, domain: Domain, slot_name: Text) -> Text: + full_name = f"utter_ask_{self._form_name}_{slot_name}" + if full_name in domain.action_names: + return full_name + else: + return f"utter_ask_{slot_name}" + async def _ask_for_slot( + self, domain: Domain, nlg: NaturalLanguageGenerator, output_channel: OutputChannel, slot_name: Text, tracker: DialogueStateTracker, ) -> List[Event]: - name_of_utterance = f"utter_ask_{slot_name}" + action_to_ask_for_next_slot = action.action_from_name( - name_of_utterance, None, domain.user_actions + self._name_of_utterance(domain, slot_name), None, domain.user_actions ) events_to_ask_for_next_slot = await action_to_ask_for_next_slot.run( output_channel, nlg, tracker, domain From afad45ffd2fe9eeef8f9f5e900599ef7bf9267ba Mon Sep 17 00:00:00 2001 From: alwx Date: Wed, 24 Jun 2020 13:55:01 +0200 Subject: [PATCH 2/2] Test added! --- tests/core/actions/test_forms.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/core/actions/test_forms.py b/tests/core/actions/test_forms.py index 4e05c35329bc..94c0b985ac97 100644 --- a/tests/core/actions/test_forms.py +++ b/tests/core/actions/test_forms.py @@ -176,6 +176,32 @@ async def test_validate_slots(): ] +def test_name_of_utterance(): + form_name = "another_form" + slot_name = "num_people" + full_utterance_name = f"utter_ask_{form_name}_{slot_name}" + + domain = f""" + forms: + - {form_name}: + {slot_name}: + - type: from_text + responses: + {full_utterance_name}: + - text: "How many people?" + """ + domain = Domain.from_yaml(domain) + + action_server_url = "http:/my-action-server:5055/webhook" + + with aioresponses() as mocked: + action_server = EndpointConfig(action_server_url) + action = FormAction(form_name, action_server) + + assert action._name_of_utterance(domain, slot_name) == full_utterance_name + assert action._name_of_utterance(domain, "another_slot") == "utter_ask_another_slot" + + def test_temporary_tracker(): extra_slot = "some_slot" sender_id = "test"