diff --git a/yal/endline_terms_and_conditions.py b/yal/endline_terms_and_conditions.py index 2e313bcd..94c0010c 100644 --- a/yal/endline_terms_and_conditions.py +++ b/yal/endline_terms_and_conditions.py @@ -15,6 +15,7 @@ class Application(BaseApplication): START_STATE = "state_start_terms" + NO_CONSENT_STATE = "state_no_consent" async def state_start_terms(self): question = self._( @@ -220,7 +221,7 @@ async def state_set_reminder_timer(self): question = self._( "\n".join( [ - "[persona_emoji] No worries, we get it!", + "No worries, we get it!", "", "I'll send you a reminder message in 30 mins, so you can come back " "and answer these questions.", @@ -230,12 +231,10 @@ async def state_set_reminder_timer(self): ) ) - return WhatsAppButtonState( + return FreeText( self, question=question, - choices=[Choice("menu", "Go to main menu")], - error=get_generic_error(), - next="state_pre_mainmenu", + next=None, ) async def state_submit_terms_and_conditions_endline(self): diff --git a/yal/main.py b/yal/main.py index 52b895b1..b8d06de5 100644 --- a/yal/main.py +++ b/yal/main.py @@ -84,7 +84,12 @@ QA_RESET_FEEDBACK_TIMESTAMP_KEYWORDS = {"resetfeedbacktimestampobzvmp"} EMERGENCY_KEYWORDS = utils.get_keywords("emergency") AAQ_KEYWORDS = {"ask a question"} -EJAF_ENDLINE_SURVEY_KEYWORDS = {"answer", "yes i want to answer"} +EJAF_ENDLINE_SURVEY_KEYWORDS = { + "answer", + "yes i want to answer", + "remind me tomorrow", + "i m not interested", +} class Application( @@ -196,13 +201,25 @@ async def process_message(self, message): endline_survey_completed = self.user.metadata.get( "endline_survey_completed" ) + if ( keyword in EJAF_ENDLINE_SURVEY_KEYWORDS and baseline_survey_completed and not endline_survey_completed ): - self.user.session_id = None - self.state_name = EndlineTermsApplication.START_STATE + self.save_metadata("assessment_reminder_sent", False) + self.save_metadata("assessment_reminder_name", "") + + if keyword == "remind me tomorrow": + self.user.session_id = None + self.state_name = AssessmentApplication.REMINDER_STATE + elif keyword == "i m not interested": + self.user.session_id = None + self.state_name = EndlineTermsApplication.NO_CONSENT_STATE + else: + self.user.session_id = None + self.state_name = EndlineTermsApplication.START_STATE + # Fields that RapidPro sets after a feedback push message feedback_state = await self.get_feedback_state() if feedback_state: diff --git a/yal/tests/surveys/test_endline.py b/yal/tests/surveys/test_endline.py index d5d339c0..58e7c6a2 100644 --- a/yal/tests/surveys/test_endline.py +++ b/yal/tests/surveys/test_endline.py @@ -93,6 +93,56 @@ async def test_endline_invitation_i_want_to_answer(tester: AppTester, rapidpro_m assert user.state.name == "state_start_terms" +@pytest.mark.asyncio +async def test_endline_invitation_remind_me_tomorrow( + tester: AppTester, + rapidpro_mock, +): + user = User( + addr="278201234567", + state=StateData(), + session_id=1, + metadata={"baseline_survey_completed": True}, + ) + app = Application(user) + msg = Message( + content="Remind me tomorrow", + to_addr="27820001002", + from_addr="27820001003", + transport_name="whatsapp", + transport_type=Message.TRANSPORT_TYPE.HTTP_API, + ) + + [reply] = await app.process_message(msg) + + assert user.state.name == "state_remind_tomorrow" + + +@pytest.mark.asyncio +async def test_endline_invitation_not_interested( + tester: AppTester, + rapidpro_mock, +): + user = User( + addr="278201234567", + state=StateData(), + session_id=1, + metadata={"baseline_survey_completed": True}, + ) + app = Application(user) + msg = Message( + content="I'm not interested", + to_addr="27820001002", + from_addr="27820001003", + transport_name="whatsapp", + transport_type=Message.TRANSPORT_TYPE.HTTP_API, + ) + + [reply] = await app.process_message(msg) + + assert user.state.name == "state_no_consent" + + @pytest.mark.asyncio async def test_endline_invitation_answer(tester: AppTester, rapidpro_mock): diff --git a/yal/tests/test_endline_terms_and_condition.py b/yal/tests/test_endline_terms_and_condition.py index cadfa630..ac7b3e0b 100644 --- a/yal/tests/test_endline_terms_and_condition.py +++ b/yal/tests/test_endline_terms_and_condition.py @@ -96,7 +96,7 @@ async def test_state_accept_consent_reminder(tester: AppTester, rapidpro_mock): message = "\n".join( [ - "🤖 No worries, we get it!", + "No worries, we get it!", "", "I'll send you a reminder message in 30 mins, so you can come back" " and answer these questions.",