async def run(self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict) -> List[EventType]: bind_logger(tracker) events = [SlotSet(SELF_ASSESS_DONE_SLOT, True)] ## Filling empty slots with previous day values slots_to_add = {} for last_slot in LAST_ASSESSMENT_SLOTS: current_slot = last_slot.replace(LAST_PREFIX, "") if tracker.get_slot(current_slot) is None: value = tracker.get_slot(last_slot) slots_to_add.update({current_slot: value}) try: save_assessment({**tracker.current_slot_values(), **slots_to_add}) except: logger.warn("Failed to save assessment", exc_info=True) if tracker.get_slot(SYMPTOMS_SLOT) == Symptoms.SEVERE: try: cancel_reminder(tracker.current_slot_values()) except: logger.warn("Failed to cancel reminder", exc_info=True) return events + [ SlotSet(key, value) for key, value in slots_to_add.items() ]
def test_cancel_reminder(self, mock_session_factory, mock_decode_reminder_id): mock_session = mock_session_factory.return_value mock_session.query.return_value.get.return_value = DEFAULT_REMINDER cancel_reminder(DEFAULT_DAILY_CI_SLOTS) self.assertIs(DEFAULT_REMINDER.is_canceled, True)
def test_cancel_reminder_with_555_phone_number_does_nothing( self, mock_session_factory, mock_decode_reminder_id): mock_session = mock_session_factory.return_value mock_session.query.return_value.get.return_value = DEFAULT_REMINDER cancel_reminder({ **DEFAULT_SELF_ASSESSMENT_SLOTS, PHONE_NUMBER_SLOT: "12225554444" }) mock_session.add.assert_not_called()
def run( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> List[Dict[Text, Any]]: bind_logger(tracker) dispatcher.utter_message( template="utter_daily_ci__early_opt_out__acknowledge_cancel_ci") dispatcher.utter_message( template="utter_daily_ci__early_opt_out__cancel_ci_recommendation") cancel_reminder(tracker.current_slot_values()) return [SlotSet(CONTINUE_CI_SLOT, False)]
def test_cancel_reminder_missing_metadata(self, mock_session_factory, mock_decode_reminder_id): mock_session = mock_session_factory.return_value mock_session.query.return_value.get.return_value = DEFAULT_REMINDER daily_ci_slots_without_metadata = dissoc(DEFAULT_DAILY_CI_SLOTS, METADATA_SLOT) with self.assertRaises(expected_exception=Exception): # None metadata cancel_reminder(daily_ci_slots_without_metadata) with self.assertRaises(expected_exception=Exception): # Empty metadata cancel_reminder({ **daily_ci_slots_without_metadata, METADATA_SLOT: {} }) mock_session.add.assert_not_called()
def submit( self, dispatcher: CollectingDispatcher, tracker: Tracker, domain: Dict[Text, Any], ) -> List[Dict]: # Mandatory check-in if _mandatory_ci(tracker): dispatcher.utter_message( template="utter_daily_ci__keep_or_cancel__feel_worse_keep_ci") dispatcher.utter_message( template= "utter_daily_ci__keep_or_cancel__feel_worse_recommendation") _recommendations(dispatcher, tracker, domain) # Optional check-in cancel elif tracker.get_slot(CANCEL_CI_SLOT) is True: dispatcher.utter_message( template="utter_daily_ci__keep_or_cancel__acknowledge_cancel_ci" ) dispatcher.utter_message( template= "utter_daily_ci__keep_or_cancel__cancel_ci_recommendation") try: cancel_reminder(tracker.current_slot_values()) except: pass else: # Optional check-in continue dispatcher.utter_message( template= "utter_daily_ci__keep_or_cancel__acknowledge_continue_ci") if tracker.get_slot(SYMPTOMS_SLOT) != Symptoms.NONE: _recommendations(dispatcher, tracker, domain) return []