Skip to content

Commit

Permalink
Attach Tracker State to OutputChannel (#619)
Browse files Browse the repository at this point in the history
* attach tracker state to channel

* add changelog

* update type hint for OutputChannel

* Update changelog/619.improvement.md

Co-authored-by: aleksandarmijat <162149565+aleksandarmijat@users.noreply.github.com>

---------

Co-authored-by: aleksandarmijat <162149565+aleksandarmijat@users.noreply.github.com>
  • Loading branch information
vcidst and aleksandarmijat authored May 24, 2024
1 parent dc94f09 commit 7ad5602
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions changelog/619.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adds `tracker_state` attribute to `OutputChannel`. It simplifies the access of tracker state for custom channel connector with `CollectingOutputChannel.tracker_state`.
8 changes: 8 additions & 0 deletions rasa/core/channels/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
from rasa.shared.constants import DOCS_BASE_URL, DEFAULT_SENDER_ID
from rasa.core.constants import BEARER_TOKEN_PREFIX
from rasa.shared.exceptions import RasaException
from rasa.shared.core.trackers import (
DialogueStateTracker,
EventVerbosity,
)

try:
from urlparse import urljoin
Expand Down Expand Up @@ -227,6 +231,10 @@ def name(cls) -> Text:
"""Every output channel needs a name to identify it."""
return cls.__name__

def attach_tracker_state(self, tracker: DialogueStateTracker) -> None:
"""Attaches the current tracker state to the output channel."""
self.tracker_state = tracker.current_state(EventVerbosity.AFTER_RESTART)

async def send_response(self, recipient_id: Text, message: Dict[Text, Any]) -> None:
"""Send a message to the client."""
if message.get("quick_replies"):
Expand Down
6 changes: 4 additions & 2 deletions rasa/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -1006,9 +1006,11 @@ async def execute_side_effects(
self,
events: List[Event],
tracker: DialogueStateTracker,
output_channel: OutputChannel,
output_channel: Optional[OutputChannel],
) -> None:
"""Send bot messages, schedule and cancel reminders."""
"""Attach tracker, send bot messages, schedule and cancel reminders."""
if output_channel:
output_channel.attach_tracker_state(tracker)
await self._send_bot_messages(events, tracker, output_channel)
await self._schedule_reminders(events, tracker, output_channel)
await self._cancel_reminders(events, tracker)
Expand Down

0 comments on commit 7ad5602

Please sign in to comment.