Skip to content

Commit

Permalink
Merge pull request #6472 from RasaHQ/trigger-intent-channel
Browse files Browse the repository at this point in the history
Keep latest_input_channel when triggering intents
  • Loading branch information
federicotdn authored Sep 8, 2020
2 parents f62839e + bcb6eea commit 8ea4169
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/6472.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Do not modify conversation tracker's ``latest_input_channel`` property when using ``POST /trigger_intent`` or ``ReminderScheduled``.
5 changes: 4 additions & 1 deletion rasa/core/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,13 +402,16 @@ def apply_to(self, tracker: "DialogueStateTracker") -> None:

@staticmethod
def create_external(
intent_name: Text, entity_list: Optional[List[Dict[Text, Any]]] = None
intent_name: Text,
entity_list: Optional[List[Dict[Text, Any]]] = None,
input_channel: Optional[Text] = None,
) -> "UserUttered":
return UserUttered(
text=f"{EXTERNAL_MESSAGE_PREFIX}{intent_name}",
intent={INTENT_NAME_KEY: intent_name},
metadata={IS_EXTERNAL: True},
entities=entity_list or [],
input_channel=input_channel,
)


Expand Down
9 changes: 8 additions & 1 deletion rasa/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,14 @@ async def trigger_external_user_uttered(
f"Invalid entity specification: {entities}. Assuming no entities."
)
entity_list = []
tracker.update(UserUttered.create_external(intent_name, entity_list))

# Set the new event's input channel to the latest input channel, so
# that we don't lose this property.
input_channel = tracker.get_latest_input_channel()

tracker.update(
UserUttered.create_external(intent_name, entity_list, input_channel)
)
await self._predict_and_execute_next_action(output_channel, tracker)
# save tracker state to continue conversation from this state
self._save_tracker(tracker)
Expand Down
19 changes: 19 additions & 0 deletions tests/core/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,25 @@ async def test_reminder_scheduled(
assert t.events[-1] == ActionExecuted("action_listen")


async def test_trigger_external_latest_input_channel(
default_channel: CollectingOutputChannel, default_processor: MessageProcessor
):
sender_id = uuid.uuid4().hex
tracker = default_processor.tracker_store.get_or_create_tracker(sender_id)
input_channel = "test_input_channel_external"

tracker.update(UserUttered("test1"))
tracker.update(UserUttered("test2", input_channel=input_channel))

await default_processor.trigger_external_user_uttered(
"test3", None, tracker, default_channel
)

tracker = default_processor.tracker_store.retrieve(sender_id)

assert tracker.get_latest_input_channel() == input_channel


async def test_reminder_aborted(
default_channel: CollectingOutputChannel, default_processor: MessageProcessor
):
Expand Down

0 comments on commit 8ea4169

Please sign in to comment.