async def handle_reminder( self, reminder_event: ReminderScheduled, sender_id: Text, output_channel: OutputChannel, nlg: NaturalLanguageGenerator, ) -> None: """Handle a reminder that is triggered asynchronously.""" tracker = self._get_tracker(sender_id) if not tracker: logger.warning( f"Failed to retrieve or create tracker for sender '{sender_id}'." ) return None if (reminder_event.kill_on_user_message and self._has_message_after_reminder(tracker, reminder_event) or not self._is_reminder_still_valid(tracker, reminder_event)): logger.debug("Canceled reminder because it is outdated. " "(event: {} id: {})".format( reminder_event.action_name, reminder_event.name)) else: # necessary for proper featurization, otherwise the previous # unrelated message would influence featurization tracker.update(UserUttered.empty()) action = self._get_action(reminder_event.action_name) should_continue = await self._run_action(action, tracker, output_channel, nlg) if should_continue: user_msg = UserMessage(None, output_channel, sender_id) await self._predict_and_execute_next_action(user_msg, tracker) # save tracker state to continue conversation from this state self._save_tracker(tracker)
def _get_slots_sub_state( tracker: "DialogueStateTracker", ) -> Dict[Text, Union[Text, Tuple[float]]]: """Set all set slots with the featurization of the stored value Args: tracker: dialog state tracker containing the dialog so far Returns: a dictionary mapping slot names to their featurization """ # proceed with values only if the user of a bot have done something # at the previous step i.e., when the state is not empty. if tracker.latest_message == UserUttered.empty( ) or not tracker.latest_action: return {} slots = {} for slot_name, slot in tracker.slots.items(): if slot is not None and slot.as_feature(): if slot.value == SHOULD_NOT_BE_SET: slots[slot_name] = SHOULD_NOT_BE_SET elif any(slot.as_feature()): # only add slot if some of the features are not zero slots[slot_name] = tuple(slot.as_feature()) return slots
def _reset(self) -> None: """Reset tracker to initial state - doesn't delete events though!.""" self._reset_slots() self._paused = False self.latest_action_name = None self.latest_message = UserUttered.empty() self.latest_bot_utterance = BotUttered.empty() self.followup_action = ACTION_LISTEN_NAME self.active_form = {}