Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ValidationAction dispatching of BotUttered messages #11394

Merged
merged 6 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/11394.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Enables the dispatching of bot messages returned as events by slot validation actions.
4 changes: 4 additions & 0 deletions rasa/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,17 @@ 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])
logger.debug(
f"Default action '{ACTION_EXTRACT_SLOTS}' was executed, "
f"resulting in {len(extraction_events)} events: {events_as_str}"
)

return tracker

async def predict_next_for_sender_id(
Expand Down
63 changes: 63 additions & 0 deletions tests/core/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="This is a test.",
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