From 6e062401f5f71c6c9a64c704e8aad22e65aae0fb Mon Sep 17 00:00:00 2001 From: Anca Lita <27920906+ancalita@users.noreply.github.com> Date: Thu, 28 Jul 2022 10:21:03 +0200 Subject: [PATCH 1/4] apply fix and add unit test --- rasa/core/processor.py | 2 ++ tests/core/test_processor.py | 63 ++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/rasa/core/processor.py b/rasa/core/processor.py index 78ee39aa3c0c..346830191c28 100644 --- a/rasa/core/processor.py +++ b/rasa/core/processor.py @@ -180,6 +180,8 @@ async def run_action_extract_slots( f"Default action '{ACTION_EXTRACT_SLOTS}' was executed, " f"resulting in {len(extraction_events)} events: {events_as_str}" ) + await self.execute_side_effects(extraction_events, tracker, output_channel) + return tracker async def predict_next_for_sender_id( diff --git a/tests/core/test_processor.py b/tests/core/test_processor.py index 0654c247b0fb..a36d3bf92bfc 100644 --- a/tests/core/test_processor.py +++ b/tests/core/test_processor.py @@ -1599,3 +1599,66 @@ async def test_custom_action_triggers_action_extract_slots( isinstance(e, BotUttered) and e.text == "Great, carry on!" for e in tracker.events ) + + +async def test_processor_executes_bot_uttered_returned_by_action_extract_slots( + default_agent: Agent, +): + slot_name = "location" + domain_yaml = textwrap.dedent( + f""" + version: "{LATEST_TRAINING_DATA_FORMAT_VERSION}" + + intents: + - inform + + entities: + - {slot_name} + + slots: + {slot_name}: + type: text + influence_conversation: false + mappings: + - type: from_entity + entity: {slot_name} + + actions: + - action_validate_slot_mappings + """ + ) + domain = Domain.from_yaml(domain_yaml) + processor = default_agent.processor + processor.domain = domain + + action_server_url = "http:/my-action-server:5055/webhook" + processor.action_endpoint = EndpointConfig(action_server_url) + + sender_id = uuid.uuid4().hex + message = UserMessage( + text="I would like to travel to Lisbon", + output_channel=CollectingOutputChannel(), + sender_id=sender_id, + parse_data={ + "intent": {"name": "inform", "confidence": 1}, + "entities": [{"entity": slot_name, "value": "Lisbon"}], + }, + ) + + bot_uttered_text = "This city is not yet supported." + + with aioresponses() as mocked: + mocked.post( + action_server_url, + payload={ + "events": [ + {"event": "bot", "text": bot_uttered_text}, + {"event": "slot", "name": "location", "value": None} + ] + }, + ) + responses = await processor.handle_message(message) + assert any(bot_uttered_text in r.get("text") for r in responses) + + tracker = await processor.get_tracker(sender_id) + assert tracker.get_slot(slot_name) is None From f4922248d174416b38ce6ac2be0052509b37752b Mon Sep 17 00:00:00 2001 From: Anca Lita <27920906+ancalita@users.noreply.github.com> Date: Thu, 28 Jul 2022 10:26:28 +0200 Subject: [PATCH 2/4] code quality fix, add changelog entry --- changelog/11394.bugfix.md | 1 + tests/core/test_processor.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 changelog/11394.bugfix.md diff --git a/changelog/11394.bugfix.md b/changelog/11394.bugfix.md new file mode 100644 index 000000000000..8b544ac8cd1e --- /dev/null +++ b/changelog/11394.bugfix.md @@ -0,0 +1 @@ +Enables the execution of side effects of running custom validation actions such as dispatching bot messages. diff --git a/tests/core/test_processor.py b/tests/core/test_processor.py index a36d3bf92bfc..a6ecceff8bb4 100644 --- a/tests/core/test_processor.py +++ b/tests/core/test_processor.py @@ -1602,7 +1602,7 @@ async def test_custom_action_triggers_action_extract_slots( async def test_processor_executes_bot_uttered_returned_by_action_extract_slots( - default_agent: Agent, + default_agent: Agent, ): slot_name = "location" domain_yaml = textwrap.dedent( @@ -1653,7 +1653,7 @@ async def test_processor_executes_bot_uttered_returned_by_action_extract_slots( payload={ "events": [ {"event": "bot", "text": bot_uttered_text}, - {"event": "slot", "name": "location", "value": None} + {"event": "slot", "name": "location", "value": None}, ] }, ) From 64451d275fadee6241d4b4dc135378159a911606 Mon Sep 17 00:00:00 2001 From: Anca Lita <27920906+ancalita@users.noreply.github.com> Date: Mon, 1 Aug 2022 14:48:01 +0200 Subject: [PATCH 3/4] address review comments --- rasa/core/processor.py | 4 +++- tests/core/test_processor.py | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/rasa/core/processor.py b/rasa/core/processor.py index 346830191c28..a1597e1d2669 100644 --- a/rasa/core/processor.py +++ b/rasa/core/processor.py @@ -173,6 +173,9 @@ async def run_action_extract_slots( extraction_events = await action_extract_slots.run( output_channel, self.nlg, tracker, self.domain ) + + await self._send_bot_messages(extraction_events, tracker, output_channel) + tracker.update_with_events(extraction_events, self.domain) events_as_str = "\n".join([str(e) for e in extraction_events]) @@ -180,7 +183,6 @@ async def run_action_extract_slots( f"Default action '{ACTION_EXTRACT_SLOTS}' was executed, " f"resulting in {len(extraction_events)} events: {events_as_str}" ) - await self.execute_side_effects(extraction_events, tracker, output_channel) return tracker diff --git a/tests/core/test_processor.py b/tests/core/test_processor.py index a6ecceff8bb4..19182691a579 100644 --- a/tests/core/test_processor.py +++ b/tests/core/test_processor.py @@ -1636,7 +1636,7 @@ async def test_processor_executes_bot_uttered_returned_by_action_extract_slots( sender_id = uuid.uuid4().hex message = UserMessage( - text="I would like to travel to Lisbon", + text="This is a test.", output_channel=CollectingOutputChannel(), sender_id=sender_id, parse_data={ From ecb5b09bed4d0bac689c6dd6824a4d0955850dfb Mon Sep 17 00:00:00 2001 From: Anca Lita <27920906+ancalita@users.noreply.github.com> Date: Thu, 4 Aug 2022 15:40:58 +0100 Subject: [PATCH 4/4] edit changelog entry --- changelog/11394.bugfix.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/11394.bugfix.md b/changelog/11394.bugfix.md index 8b544ac8cd1e..df483db5f869 100644 --- a/changelog/11394.bugfix.md +++ b/changelog/11394.bugfix.md @@ -1 +1 @@ -Enables the execution of side effects of running custom validation actions such as dispatching bot messages. +Enables the dispatching of bot messages returned as events by slot validation actions.