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

Metada on session start action #5611

Merged
merged 23 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
e312191
The default action 'action_session_start' wasn't
lluchini Apr 9, 2020
b53cdb1
Updating doc string for:
lluchini Apr 9, 2020
09260e3
PEP8 - line too long adjust.
lluchini Apr 9, 2020
91834f9
Merge branch 'master' into metada-on-session-start-action
lluchini Apr 9, 2020
376e90f
Appended test to improved functionality
lluchini Apr 9, 2020
e4b3e6a
Adding changelog.
lluchini Apr 10, 2020
2b79796
Merge branch 'master' into metada-on-session-start-action
degiz Apr 16, 2020
c41c084
Update tests/core/test_actions.py
lluchini Apr 16, 2020
0bd3d3b
Adjust suggested by degiz (https://github.com/degiz)
lluchini Apr 16, 2020
e56e176
Merge branch 'master' into metada-on-session-start-action
lluchini Apr 16, 2020
f9bb458
Most high level (in terms of structure) code we've
lluchini Apr 17, 2020
ef00657
Merge branch 'master' into metada-on-session-start-action
lluchini Apr 17, 2020
d633cf6
DeepSource identified a patern break,
lluchini Apr 17, 2020
2a3e2de
DeepSource identified a patern break,
lluchini Apr 17, 2020
afc0263
The deep source is faling without reason,
lluchini Apr 17, 2020
26b1cad
Update changelog/5574.bugfix.rst
lluchini Apr 17, 2020
4f9f05b
Update tests/core/test_processor.py
lluchini Apr 17, 2020
2dadeb6
Removed by sugestion of degiz
lluchini Apr 17, 2020
c7e7d7f
Merge branch 'master' into metada-on-session-start-action
degiz Apr 21, 2020
5735c93
Merge branch 'master' into metada-on-session-start-action
degiz Apr 22, 2020
4243dfd
Merge branch 'master' into metada-on-session-start-action
degiz Apr 22, 2020
ac060c9
Merge branch 'master' into metada-on-session-start-action
degiz Apr 22, 2020
b759106
Merge branch 'master' into metada-on-session-start-action
degiz Apr 22, 2020
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/5574.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed issue where metadata was not being sent with the tracker from session_start event when calling action server.
lluchini marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 10 additions & 2 deletions rasa/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
ReminderScheduled,
SlotSet,
UserUttered,
SessionStarted,
)
from rasa.core.interpreter import (
INTENT_MESSAGE_PREFIX,
Expand Down Expand Up @@ -175,13 +176,17 @@ async def _update_tracker_session(
)

async def get_tracker_with_session_start(
self, sender_id: Text, output_channel: Optional[OutputChannel] = None
self,
sender_id: Text,
output_channel: Optional[OutputChannel] = None,
metadata: Optional[Dict] = None,
) -> Optional[DialogueStateTracker]:
"""Get tracker for `sender_id` or create a new tracker for `sender_id`.

If a new tracker is created, `action_session_start` is run.

Args:
metadata: Data sent from client associated with the incoming user message.
output_channel: Output channel associated with the incoming user message.
sender_id: Conversation ID for which to fetch the tracker.

Expand All @@ -193,6 +198,9 @@ async def get_tracker_with_session_start(
if not tracker:
return None

if metadata:
lluchini marked this conversation as resolved.
Show resolved Hide resolved
tracker.events.append(SessionStarted(metadata=metadata))

await self._update_tracker_session(tracker, output_channel)

return tracker
Expand Down Expand Up @@ -233,7 +241,7 @@ async def log_message(
# we have a Tracker instance for each user
# which maintains conversation state
tracker = await self.get_tracker_with_session_start(
message.sender_id, message.output_channel
message.sender_id, message.output_channel, message.metadata
)

if tracker:
Expand Down
15 changes: 15 additions & 0 deletions tests/core/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,21 @@ async def test_action_session_start_without_slots(
assert events == [SessionStarted(), ActionExecuted(ACTION_LISTEN_NAME)]


async def test_action_session_start_with_metada(
lluchini marked this conversation as resolved.
Show resolved Hide resolved
default_channel: CollectingOutputChannel,
template_nlg: TemplatedNaturalLanguageGenerator,
template_sender_tracker: DialogueStateTracker,
default_domain: Domain,
):
template_sender_tracker.events.append(
SessionStarted(metadata={"metadataTestKey": "metadataTestValue"})
)

await test_action_session_start_without_slots(
default_channel, template_nlg, template_sender_tracker, default_domain
)


@pytest.mark.parametrize(
"session_config, expected_events",
[
Expand Down